Deduce output.

Can anyone explain to me how to get this output? :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
	int p,q,r;
	for(p=4; p<13; p++)
	{
		r=++p;
		for(q=18; q<=15; q--)
		{
			r+=p*q;
			r-=13;
		}
		cout<<r<<endl;
	}
   system("Pause");
   return 0;
}


OUTPUT:
5
7
9
11
13
Last edited on
1
2
3
4
5
for(q=18; q<=15; q--)
{
    r+=p*q;
    r-=13;
}

This for loop will never run as the condition will always be false. That is, 18 <= 15 == false, so we can take that out of the code.

Now, we end up with this simple snippet.
1
2
3
4
5
for(p=4; p<13; p++)
{
    r=++p;
    cout<<r<<endl;
}

The above is pretty self explanatory.
@integralfx Thank for the reply once again. okay I got it. Thanks a lot ! :D
Topic archived. No new replies allowed.