Nested For

Example 1:
# include <iostream.h>
# include <conio.h>

main()
{

int loop,counter;
clrscr();

for(counter=0;counter<5;counter++)
{
for(loop=0;loop<counter;loop++)
{
cout <<counter;
}
cout <<"\n";
}

getch();
}
Example 2:
# include <iostream.h>
# include <conio.h>

main()
{

int bil,loop,counter;
clrscr();

cout <<"Masukkan sembarang bilangan ! : ";
cin >>bil;

for(counter=0;counter<=bil;counter++)
{
for(loop=1;loop<counter;loop++)
{
cout <<"*";
}
cout <<"\n";
}
for(counter=bil;counter>=0;counter--)
{
for(loop=2;loop<counter;loop++)
{
cout <<"*";
}
cout <<"\n";
}

getch();
}

Posted in . Bookmark the permalink. RSS feed for this post.

Leave a Reply

Search

Support by Blogger ITN | Converted by LiteThemes.com