#include <iostream>
using namespace std;
void main()
{
int i,j,r;
cout<<"Input number of rows (half of the diamond) :";
cin>>r;
for(i=0;i<=r;i++)
{
for(j=1;j<=r-i;j++)
cout<<" ";
for(j=1;j<=2*i-1;j++)
cout<<"*";
cout<<endl;
}
for(i=r-1;i>=1;i--)
{
for(j=1;j<=r-i;j++)
cout<<" ";
for(j=1;j<=2*i-1;j++)
cout<<"*";
cout<<endl;
}
system ("pause");
}
using namespace std;
void main()
{
int i,j,r;
cout<<"Input number of rows (half of the diamond) :";
cin>>r;
for(i=0;i<=r;i++)
{
for(j=1;j<=r-i;j++)
cout<<" ";
for(j=1;j<=2*i-1;j++)
cout<<"*";
cout<<endl;
}
for(i=r-1;i>=1;i--)
{
for(j=1;j<=r-i;j++)
cout<<" ";
for(j=1;j<=2*i-1;j++)
cout<<"*";
cout<<endl;
}
system ("pause");
}
Output:
*
***
*****
*******
*********
*******
*****
***
*
Write a program in C++ to display the pattern like a diamond
Reviewed by Unknown
on
May 30, 2017
Rating:
No comments: