Home » Unlabelled » C++ Diamond pattern
Sunday, 28 December 2014
C++ Diamond pattern
//This programme is tested on visual studio 2012//
#include<iostream>
using namespace std;
void main()
{
int n,c=3,t,l=1;
cout<<"------------------------------------------------------------------------------\n";
cout<<"This programme will print a specific Diamond pattern on entering number greater than 1\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"Enter Size of Diamond\nSize :- ";
cin>>n;
while(n<2)
{
cout<<"Youentered invalid input please enter number greater than 1";
cout<<"------------------------------------------------------------------------------\n";
cout<<"This programme will print a specific Diamond pattern on entering number greater than 0\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"Enter Size of Diamond\nSize :- ";
cin>>n;
}
t=n;
for(int i=1;i<=n;i++)
{
if(i<=n)
{
for(int j=1;j<=t;j++)
cout<<" ";
t--;
for(int k=1;k<=n;k++)
cout<<"*";
for(int m=1;m<l;m++)
cout<<" ";
l=l+2;
for(int z=1;z<=n;z++)
cout<<"*";
c=c+2;
}
cout<<endl;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=t;j++)
cout<<" ";
t++;
for(int k=1;k<=n;k++)
cout<<"*";
if(i==2*n)
{
for(int cn=1;cn<=n;cn++)
cout<<"*";
}
else
{
for(int m=1;m<l;m++)
cout<<" ";
l=l-2;
for(int z=1;z<=n;z++)
cout<<"*";
c=c+2;
}
cout<<endl;
}
for(int w=1;w<=n;w++)
cout<<" ";
for(int q=1;q<=2*n;q++)
cout<<"*";
cout<<endl;
cout<<"\n\n------------------------------------------------------------------------------\n";
cout<<"Thank You for using.\n\nVisit http://bilalzahid22.blogspot.com/ for more\n";
cout<<"\n------------------------------------------------------------------------------\n";
system("pause");
}
Lihat juga Artikel dari
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment