c - for loop not incrementing counter in gcc -
i'm using gcc 4.9.2 , have program print sum of 4th powers of n numbers.
i have written program sum printed out 4th power of number entered , not sum. think problem counter don't know what.
if(n>0 && n<=40) { for(c=0;c<=n;c++) { s=0; s=s+c*c*c*c; } printf("%d",s); }
because set
s=0;
inside loop.
put outside loop.
if(n>0 && n<=40) { s=0; for(c=0;c<=n;c++) { s=s+c*c*c*c; } printf("%d",s); }
btw: for-loop can changed to:
for(c=1;c<=n;c++)
because value c=0 doesn't change anything.
Comments
Post a Comment