Thursday, 15 January 2015

C++ code to print diamond (size = even no)

#include<iostream>
using namespace std;
void main()
{
int size,newsize,n,p,controller,size2;
cout<<"Enter size any even number";
cin>>size;
n=size/2;
p=size-2;
size2=0;
controller=size-p;
for(int i=0;i<n;i++)
{
newsize=n-i;
for(int j=1;j<newsize;j++)
{
cout<<" ";
}
for(int k=1;k<=controller;k++)
{
cout<<"*";
}
if(p>0)
p=p-2;
controller=size-p;
cout<<endl;
}
p=size-2;
n=size/2;
for(int l=1;l<n;l++)
{
size2=n-l;
for(int m=size2;m<n;m++)
{
cout<<" ";
}

for(int c=1;c<=p;c++)
{
cout<<"*";
}
p=p-2;
cout<<endl;

}
}



No comments:

Post a Comment