Sunday, August 2, 2009

Can someone show me what this program would look like in C++ language?

Write a C++ program that adds all the even numbers from 1 to 40 except 4 and 10.





Use FOR loop or WHILE loop.





thanks!

Can someone show me what this program would look like in C++ language?
int i, total;


for(i=1;i%26lt;=40;i++){


if(i % 2) = 0 //the current number is divisble by 2


{


if(i != 4 %26amp;%26amp; i != 10){


total *= i;


}


}


loop








Something like that. I didn't compile it so the errors are free of charge.
Reply:int total=0;


for (int i=1; i%26lt;=40; i++)


{


 if (((i % 2)==0) %26amp;%26amp; (i!=4) %26amp;%26amp; (i!=10)) total+=i;


}


No comments:

Post a Comment