Sunday 2 June 2013

Program to print pyramids on screen

PROGRAM   TO    PRINT    PYRAMIDS      IN        C++

PROGRAM #1




#include<iostream.h>
#include<conio.h>
void main()
{
int k,n=5;
clrscr();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if (j==i)
{
cout<<"1";
}
else
{
cout<<"2";
}
}
 cout<<"\n";
  }
  getch();
}


PROGRAM #2





#include<iostream.h>
#include<conio.h>
main()
{
int n=3;
clrscr();
for (int i=0;i<n;i++)
{
for(int k=0;k<i;k++)
{
cout<<" ";
}

for(int j=n-i;j>0;j--)
{
cout<<"*";
}
cout<<"\n";
}
getch();
}


PROGRAM #2







#include<iostream.h>
#include<conio.h>
main()
{
int n=3;
clrscr();
for (int i=0;i<n;i++)
{

for(int j=n-i;j>0;j--)
{

cout<<"*";
}
cout<<"\n";
}
getch();
}


PROGRAM #3





#include<iostream.h>
#include<conio.h>
main()
{
int n=5;
clrscr();
for (int i=0;i<n;i++)
{
for(int k=0;k<i;k++)
{
cout<<" ";
}

for(int j=n-i;j>0;j--)
{
cout<<"* ";
}
cout<<"\n";

}
getch();
}


PROGRAM #4






#include<iostream.h>
#include<conio.h>
main()
{
int n=4;
clrscr();
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i;j++)
{
cout<<" ";
}
cout<<"*";
for(int k=0;k<i;k++)
{
cout<<" *";
}
cout<<"\n";
}
getch();
}



Share this

3 Responses to "Program to print pyramids on screen "

  1. these are quite understable ........... plz post more like these

    ReplyDelete
  2. These are supposed to be hard?

    ReplyDelete