// Program to print a diamond shape
#include <iostream.h>
#include <conio.h>
main()
{
int i,j,k,s,n,m;
clrscr();
cout << "Enter the value of m: ";
cin >> m;
n = (2*m)-1;
for(i = 1, s = n; i <= n; i++,s--)
{
for(k = 1; k < s; k++)
cout << " ";
for(j = 1; j <= i; j++)
{
cout << "* ";
}
cout << "\n";
}
for(i = (n-1), s = 1; i >= 1; i--, s++)
{
for(k = 1; k <= s; k++)
cout << " ";
for(j = 1; j <= i; j++)
{
cout << "* ";
}
cout << "\n";
}
getch();
}
Output :
No comments:
Post a Comment