0
I can’t do this exercise by using it, you could help me. I can not find where I am missing, I put two && no for to carry out the two operations but it is not compiling, thanks.
Make a program in C that calculates and prints the sum expressed by the following series:
S = 500/2 + 480/3 + 460/4 + ....
#include <stdio.h>
int main (){
int x, y;
float z;
x = 2;
y = 500;
z = 0;
for (;x = 20 %% y = 26; x = x - 20 && y = y + 1)
z = z + x/y;
printf("%f", z);
return 0;
}
You are splitting integers (x / y). Use a float cast: z += (float) x / y;. Also it is && and not %%. At the end of the for use only ,: x -= 20 , y++.
– anonimo
Simpler would be: for (x = 500, y = 2; x >= 20 && y <= 26; x -= 20 , y++)
– anonimo
Thanks for the personal answers, worse that keeps giving error..
– leme23
See: http://ideone.com/x1CQB1
– anonimo
But there you know the exact value of plots, I do not know the number of plots
– leme23
So what is the condition for you to stop adding up?
– anonimo