Please tell me of these are nested loops??????

closed account (18RGNwbp)
Is this a nested loop??? The code does what I want it to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 //#include <stdafx.h>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

    int main ()
    {

    int A, B, C ; //Sides and the hypotenuse of the triangle
    int counter; //Counts how many triples there are

     counter = 0;



        cout << "\tLIST OF PYTHAGOREAN TRIPLES:\n" << endl;
        for (C=1; C <=17;  C++)
        for (B=1; B <= 8; B++)
        for (A=1; A <= 15;  A++)

                if (A*A + B*B == C*C)
                {
                   cout << setw(10) <<  A;
                   cout << setw(12) <<  B;
                   cout << setw(12) <<  C << endl;
                   counter = counter + 1;
                }

        return 0;
    }
Yes it is, but might i make a suggestion?

1
2
3
4
5
6
7
8
9
10
11
12
13
for ( C blah blah blah )
{
    for ( B blah )
    {
        for ( A Blah )
        {
            if( blah )
            {
                
            }
        }
    }
}


bracket off the for loops, it looks nicer IMO and you avoid problems such, in this case your loop wouldnt run anything past the if statement
Topic archived. No new replies allowed.