Wednesday, 8 July 2015

Daimond pattern by inputing number of rows in C++

#include<iostream>
using namespace std;
int main()
{
int n,c,f,space=1;
cout<<"enter a num of rows: ";
cin>>n;
space=n-1;
for(f=1; f<=n; f++)
{
for(c=0; c<space; c++)
cout<<" ";
space--;
for(c=0; c<2*f-1; c++)
cout<<"*";
cout<<endl;
}
space=1;
for(f=1; f<=n-1; f++){
for(c=1; c<=space; c++)
cout<<" ";
space++;
for(c=1; c<=2*(n-f)-1; c++)
cout<<"*";
cout<<endl;
    }

}

0 comments:

Post a Comment