Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

why these two loops does not give the same result? #include #include int main() { int i, sum1=0,sum2=0; for (i=26; i>=6; i-=2) sum1+=i*i*i; printf("Sum i^3 for: %d", sum1); i=26; while (i>=6) { if (i==16) break; sum2+=i*i*i; i-=2; } printf("\n\nSum i^3 while, 16: %d\n", sum2); return 0; } why these two loops does not give the same result? #include #include int main() { int i, sum1=0,sum2=0; for (i=26; i>=6; i-=2) sum1+=i*i*i; printf("Sum i^3 for: %d", sum1); i=26; while (i>=6) { if (i==16) break; sum2+=i*i*i; i-=2; } printf("\n\nSum i^3 while, 16: %d\n", sum2); return 0; } @Computer Science

OpenStudy (anonymous):

because both of them is written in such a way ...

OpenStudy (anonymous):

what way?

OpenStudy (anonymous):

Do you understand loops ?

OpenStudy (anonymous):

i think so. The thing is that i have to do it in this way. Is it completely wrong?

OpenStudy (anonymous):

what is this program doing ?

OpenStudy (anonymous):

1)Sum of i^3,if step is -3 and i<26 ,i>6 2) the same,but with WHILE and BREAk at i=16

OpenStudy (anonymous):

ps i just realized that the results have to be different :)

OpenStudy (anonymous):

Sry..

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!