I am using a nested for
loop to use to solve the given problem.
I have 4 integers to declare: i
(for initialization of the outer loop), j
(for initialization of the inner loop, s
(for displaying the sum of the series) & term
(for finding the term values in the series). up to here i'm ok with. What I do not get is the necessity in assigning s
& term
with value 0
.
Also, why is term = term +j
and s = s+term
?
int i,j,n,s,term;
s= 0;
for(i=1; i<=n; i++) {
term=0;
for(j=1; j<=i; j++) {
term = term +j;
}
s = s+term;
}