Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Nested for loops (http://www.go4expert.com/forums/nested-for-loops-t22202/)

donalt 26May2010 03:56

Nested for loops
 
hi,

iam trying to write a program using nested for loops which will display the following
*
**
***
****
*****
******
*******
********

bluecoder 26May2010 23:34

Re: Nested for loops
 
what have you done so far ?

xpi0t0s 27May2010 12:24

Re: Nested for loops
 
This is very easy. Your subject line contains the key. A nested for loop is simply one loop inside another, e.g.:
Code:

for (int i=0; i<10; i++)
{
    for (int j=0; j<10; j++)
    {
        printf("%d %d\n",i,j);
    }
}

Start with a for loop that displays any number N of *'s (hint: a printf that displays one star inside a loop will do it). Change the value of N and check the program prints the correct number of *'s.

Then put that for loop into another for loop and vary N from 1 to the relevant maximum.

It's as simple as that!


All times are GMT +5.5. The time now is 05:11.