Q)Write a Program to Print The Following Star Pattern in c++
*
* *
* * *
* * * *
* * * * *
Sol)
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,k;
cout<<"Enter number of rows"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=n-1;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
===OUTPUT===
Enter number of rows
5
*
* *
* * *
* * * *
* * * * *
*
* *
* * *
* * * *
* * * * *
Sol)
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,k;
cout<<"Enter number of rows"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=n-1;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
===OUTPUT===
Enter number of rows
5
*
* *
* * *
* * * *
* * * * *
No comments:
Post a Comment