+ 1
Printing options
Printing options You have a document that consists of n pages and you must to print it as two pages in a paper. If n is odd number, you must add an empty page to end of the document. And now n is even 1-step: Printing odd pages 1,3,5,...,n-1 2-step. Printing even numbers from backward n,n-2,...,6,4,2 must find code for printing array of pages how to code on web?
1 ответ
+ 2
I think modulus should help you in this case. Since you didn't specify which language, here's an example in Java
public class Main {
public static void main(String[] argv) {
int x = 5;
if (x % 2 == 0) {
System.out.println("even");
}
if (x % 2 != 0) {
System.out.println("odd");
}
// ... or binary AND operator...
if ((x & 1) == 0) {
System.out.println("even");
}
if ((x & 1) != 0) {
System.out.println("odd");
}
}
}
Stolen from: http://www.java2s.com/Code/Java/Language-Basics/Detectevenoddnumberwiththemodulusoperator.htm