<de********@gmail.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
hey i wrote all my code but i need to print out only the even numbers
so is there any predefined function i can use or what can structure i
should be following?
.......
16 for(int r = 0; r < 10; r++) {
17 for(int c = 0; c < 10; c++) {
18 cout << setw(5) << setfill(' ') << r*c;
19 } // end for c
20 cout << endl;
21 }// end for r
22
........
( i thought i could make some change on line 18 so that i could get
the program worked as i would like it to; i am not sure if i am right)
When is a number even? When it is evenly divisible by 2. How can you
determine if a number is evenly divisble by 2? There are a number of ways.
One is the modulus operator. %
dividend % divisor (meh? is it dividend? can't remember)
will return a remainder.
5 % 3
will return 2. Becaue 5 / 3 = 1 with a remainer of 2. What remainder would
mean that the number is evenly devisible by 3?
Another way is to look at the bits.
1 & number
will return 1 if the 1 bit is set. The 1 bit is set if a number is odd.
What number would be returned meaning the number is even?
You will also want an if statement.
if ( somecondition )
cout << something;
It is up to you to figure out what the condition is.