Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 5, the program should display c++ look like a diamond
/*If you any query do comment in the comment section else like the solution*/
#include<iostream>
using namespace std;
int main() {
int n, i, j, k;
cout<<"Enter length of diamond: ";
cin>>n;
for(i=0;i<n;i++) {
for(j=i;j<n-1;j++) {
cout<<" ";
}
for(j=0;j<=i;j++) {
cout<<"* ";
}
cout<<endl;
}
for(i=n-1;i>=0;i--) {
for(j=n-1;j>i;j--) {
cout<<" ";
}
for(j=0;j<=i;j++) {
cout<<"* ";
}
cout<<endl;
}
}
Get Answers For Free
Most questions answered within 1 hours.