Problem Description: This program will simply print out diamond shape using C++.If you like to print a kite shape please remove the comments and run the program it will print a kite.
Note: Run this program using DevC++
Note: Run this program using DevC++
#include<iostream> using namespace std; int main() { int lines,space,stars; for(lines=1;lines<=10;lines++) { for(space=10-lines;space>=0;space--) { cout << " " ; } for(stars=1;stars<=(2*lines-1);stars++) { cout << "*" ; } cout << endl; } for(lines=9;lines>=1;lines--) { for(space=10-lines;space>=0;space--) { cout << " " ; } for(stars=1;stars<=(2*lines-1);stars++) { cout << "*" ; } cout << endl; } /* // Till Here it is Diamond Code.........After this the code is for a kite for(int i=1;i<=3;i++) { for(int j=1;j<=10;j++) { cout << " "; } for(int k=1;k<=1;k++) { cout << "*"; } cout << endl; }*/ system("pause"); return 0; }
using namespace std;
ReplyDeleteint main()
{
int N=0; int i=1; char choice; char ch;
cout<<"Enter the number of rows : ";
cin>>N;
cout<<"(H)ollow Diamond or (F)illed Diamond : ";
cin>>choice;
if(choice=='h') ch=' ';
if(choice=='f') ch='*';
int T= N+1; int h = (N/2 +1);
for(int j=1; j<=N; j++)
{
while(i<=abs(h-j)+2) {cout<<" "; i++;}
cout<<"*";
int k=abs(h-j);
while((i!=k) && (i!=T-k)) {if(j!=1 && j!=N)cout<N) break;}
if(j>1 && j<N) cout<<"*";
cout<<endl;
i=1;
}
return 0;
}