Please explain

Please explain this to me,
Find the output of the following program:
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}

First of all, code tags helps a lot.

Basically, a loop is created and each time it loops Number is divided by 10. Within that loop you are dividing Number by 10 and storing its remainder in R, you then check to see if the result in R divided by 2 has no remainder and if so you add R to your First Variable, if it does have a remainder you add R to Second.

The loop will continue until Number is 0 or lower, you are then subtracting First and Second and displaying the answer. In this case it was -2

The % is the modulo operator , see http://www.cplusplus.com/doc/tutorial/operators/ for more information. :)


I think somebody is messing with you OP. The entry point is invalid, 'iostream.h' does not exist or else it is a non-standard header file, the std namespace is not being declared but it is being used and the while condition is testing against a capitol letter 'O' not the number '0'. Where did you find this?

Yeah I corrected those in my Visual Studio and just thought those were possibly typos when he entered it on this site.
Topic archived. No new replies allowed.