This is a C++ program that uses loops to print a diamond pattern of stars. The pattern is printed in two parts - first, the upper half of the diamond is printed, and then the lower half is printed. Here is an explanation of how the program works:
#include<iostream> using namespace std; int main() { int i,j,n; cout<<"\nEnter the value:"; cin>>n; for(i=1;i<=n;i++) { cout<<"\n"; for(j=1;j<=(n-i);j++) { cout<<" "; } for(j=1;j<i;j++) { if(j==1) { cout<<" *"; } else { cout<<" "; } } for(j=1;j<=i;j++) { if(j==i) { cout<<" *"; } else { cout<<" "; } } } for(i=1;i<=n;i++) { cout<<"\n"; for(j=1;j<=i;j++) { cout<<" "; } for(j=n;j>i;j--) { if(j==n) { cout<<" *"; } else { cout<<" "; } } for(j=2;j<=(n-i);j++) { if(j==n-i) { cout<<" *"; } else { cout<<" "; } } } return 0; }To download raw file Click Here
Enter the value:10
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions