Using Nested for Loops - C Statement

C examples for Statement:for

Description

Using Nested for Loops

Demo Code

#include <stdio.h>

int main (void)
{
    int n, number, triangularNumber, counter;

    for (counter = 1; counter <= 5; ++counter)
    {/*from www  . j  av  a 2s .co  m*/
        printf ("What triangular number do you want? ");
        scanf ("%i", &number);

        triangularNumber = 0;

        for (n = 1; n <= number; ++n)
            triangularNumber += n;

        printf ("Triangular number %i is %i\n\n", number, triangularNumber);
    }
    return 0;
}

Result


Related Tutorials