Wap to print following pattern using for loop in c++ language.
// *
// * *
// * * *
// * * * *
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"enter the no of rows:";
cin>>n;
for(i=1; i<=n; i++)
{
for( j=n-i;j>=1; j--)
{
cout<<" ";
}
for(k=1; k<=i; k++)
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}
Output:-
// *
// * *
// * * *
// * * * *
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"enter the no of rows:";
cin>>n;
for(i=1; i<=n; i++)
{
for( j=n-i;j>=1; j--)
{
cout<<" ";
}
for(k=1; k<=i; k++)
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}
Output:-
No comments:
Post a Comment