How to make a diamond in C++?
#include<iostream>
using namespace std;
void star(int );
int main()
{
int n;
cout<<"Enter num of rows: ";
cin>>n;
star(n);
}
void star(int rows){
for(int i=1;i<=rows;i++){
for(int j=rows;j>=i;j--){
cout<<" ";
}
for(int x=1;x<=i;x++){
cout<<"*"<<" ";
}
cout<<endl;
}
for(int i=1;i<=rows;i++){
for(int j=0;j<=i;j++){
cout<<" ";
}
for(int x=rows;x>i;x--){
cout<<"*"<<" ";
}
cout<<endl;
}
}
0 comments:
Post a Comment