Saturday, February 19, 2011

Nested Loop Example ( A simple star program )

When Loops are used within loops then it is called as nested loops. Nested loops are almost used in most of the programs because a single loop can't fulfill our needs. For example making a program for finding prime numbers between a given range will require nested loops.

Here is a simple star program which will print the following shape

***
***
***


#include"conio.h"
#include"iostream.h"

void main()
{
clrscr();


for(int i=1;i<=3;i++)
{

for(int j=1;j<=3;j++)
{
cout<<"*";
}
cout<}

getch();
}