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
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
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 ?
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
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 :)