Problem: Shapes of Diamond and Box. //Including Libraries #include
#include <stdlib.h> #include // Begining of Program void main() { clrscr(); // Declaration of Variables int choice,length; cout<<"\n\n1-BOX\n\n2-DIAMOND\n\n3-EXIT"; cout<<"\n\nEnter Choice Number: "; cin>>choice; if (choice==1) { cout<<"\n\nEnter The Length of The Box: "; cin>>length; cout<<"\n\n"; for (int i=1;i<=length;i++) { cout<<"*"; } cout<<"\n"; for (int j=1;j<=length-2;j++) { cout<<"*"; for (int k=1;k<=length-2;k++) { cout<<" "; } cout<<"*\n"; } for (int l=1;l<=length;l++) { cout<<"*"; }
} else if (choice==2) { int a,b,c=1; cout<<"\nEnter The length of Diamond: "; cin>>a; b=a-1; clrscr(); for (int i=1;i<=b;i++) { cout<<" "; } cout<<"*\n"; for(int j=1;j<=a-1;j++) { for(i=1;i<=b-1;i++) { cout<<" "; } b--; cout<<"*"; for(int k=1;k<=c;k++) { cout<<" "; } c=c+2; cout<<"*\n"; } // Lower Side of Diamond b=a-1; if (a==4) { c=a-1; } else c=a+(a-5);
int r=1; for (j=1;j<=a-2;j++) { for (i=1;i<=r;i++) { cout<<" "; } cout<<"*"; r++; for (int t=1;t<=c;t++) { cout<<" "; } cout<<"*\n"; c=c-2; }
for ( i=1;i<=a-1;i++) { cout<<" "; } cout<<"*\n";
} else if (choice==3) exit(0); else cout<<"Wrong Entry...Press any key to Terminate the Program..."; getch(); }
Click the link below to see more examples URL: http://ravianeducation.blogspot.com E-Mail: [email protected] Farhan: 03008855006