Powered by Blogger.

Search

Saturday, 20 December 2014

C++ programme to print X pattern


//This programme is tested on visual studio 2012//
#include <iostream>
using namespace std;
void main()
{
    int n,t,c=1;
    t=1;
cout<<"------------------------------------------------------------------------------\n";
cout<<"This programme will print a X pattern on entering number greater than 1\n";
cout<<"------------------------------------------------------------------------------\n";
    cout<<"Enter number : ";
    cin>>n;
    while (n<=1)
    {
    cout<<"You entered invalid input Try again :\n";
    cout<<"Enter number";
    cin>>n;
    }
    int temp=2*n;
    for(int i=1;i<n;i++)
    {
  
        for(int j=1;j<=t;j++)
        cout<<" ";
        cout<<"*";
        for(int k=1;k<temp-2;k++)
    {
  
        cout<<" ";

}
        cout<<"*";
        cout<<endl;
        t=t+1;
        temp=temp-2;
      
    }
   
      
        for(int i=1;i<=n;i++)
    {
    if(i==1)
        {
        for(int a=1;a<=n;a++)
        {
       
        cout<<" ";
    }
        cout<<"*"<<endl;
        }
        else
        {
            for(int z=i;z<=n;z++)
            cout<<" ";
        cout<<"*";
        for(int k=i+1;k<c;k++)
        cout<<" ";
        cout<<"*"<<endl;
    }
        c=c+3;
    }
        cout<<"\n\n------------------------------------------------------------------------------\n";
    cout<<"Thank You for using.\n\nVisit http://bilalzahid22.blogspot.com/ for more\n";
  cout<<"\n------------------------------------------------------------------------------\n";
}

Ditulis Oleh : Unknown // 05:36
Kategori:

0 comments:

Post a Comment

Translate