Write a C++ program to print a pattern :

Write a C++ program to print a pattern :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

This question always asked in Technical Interview.






Program:


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{

cout<<j<<" ";
}
cout<<"\n";
}
getch();
}


output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5




No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!