Code Competitions

Coding competition

Tuesday, 28 May 2013

program to create dual connected triangle pattern

#include<iostream.h>
#include<conio.h>
void main()
{
    int i,j,n,m;
    clrscr();
    cout<<"\nEnter the value of n ";
    cin>>n;
    clrscr();
    m=n;
    for(i=1;i<=n/2+1;i++)
    {
        for(j=1;j<i;j++)
        {
            cout<<" ";
        }
        for(int k=1;k<=m;k++)
        {
            cout<<"*";
        }
        m=m-2;
        cout<<"\n";
    }
    m=n/2;
    int z=3,k;
    for(i=n/2+2;i<=n;i++)
    {
        for(j=1;j<m;j++)
        {
            cout<<" ";
        }
        m--;
        for(k=1;k<=z;k++)
        {
            cout<<"*";
        }
        z=z+2;
        cout<<"\n";
    }
    getch();
}

OUTPUT:


No comments:

Post a Comment