# Priting some of the for loop results (but not all of them)

This is a discussion on Priting some of the for loop results (but not all of them) within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I've encountered the following problem: Inside a for loop I calculate recursively the members of a mathematical series, ...

1. ## Priting some of the for loop results (but not all of them)

Hey guys,
I've encountered the following problem:
Inside a for loop I calculate recursively the members of a mathematical series, so that the result of each new calculation is dependant on the previouos calculation. I need to print (in one step) the calculation results for n = 1, 10, 100 and 1000 only, without printing all the calculations of the loop. How do I do that - I'm a beginner so I only know how to print each and every step of the calculation.

Thanks,
N.

2. If your result is given by x ...and the index by n..
Change
"cout<<x;"
to
"if(n==10||n==100||n==1000)cout<<x;"

Btw... you should post the code... as something smells wrong with your "recursion inside for loop" logic.

3. I'm trying to answer forever, but something goes wrong..Firsy=t of all, we're not allowed to use if yet. Here is the partia code:

insert
Code:
```
int main(int argc, char* argv[])
{
float Acurr = 1, Aest;
float i, j;
int k, l = 0;
for (i = 1, j = 2, k = 0; j < 10, k < 1001; i = Acurr, j++, k++){
//l++;
Acurr = i + sqrt(i) ;
Aest = (pow(j,2))/4 ;
cout << "for n =  " << k + 1  << endl;
cout << "An as calculated by the series is:  " << Acurr << endl;
cout << "An as calculated by the estimate is:  "  << Aest << endl;
cout << "The absolute difference between the two calculations is:  " << abs(Acurr - Aest);
cout << endl;
//}
}
system ("pause");
return 0;
}```

4. Originally Posted by nikky
Firsy=t of all, we're not allowed to use if yet.
Yet? It is weird for a student to be taught loops before if statements. I suggest that you check with your teacher; perhaps your teacher merely wants you to use a loop rather than a gigantic series of if statements, but an if statement within the loop body is permissible.