Showing posts with label pyramid. Show all posts
Showing posts with label pyramid. Show all posts

Saturday, March 10, 2012

Program to print the pyramid of no.

//Program to print the  pyramid of no.
              1
          1  2  3 
       1 2  3  4  5
    1 2 3  4  5  6  7
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i,g;
      y=1;
      for(x=3;x>=0;x--)
      {
      for(i=1;i<=x;i++)
       {printf("   ");
       }g=1;
       for(i=0;i<y;i++)
       {printf(" %d",g);g++;
       }
      
       y=y+2;
       printf("\n\n");
       }
       getch();
       }

Program to Print the pyramid.

//Program to Print the pyramid.
       *
     ***
   *****
 *******
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=1;
      for(x=3;x>=0;x--)
      {
      for(i=1;i<=x;i++)
       {printf(" ");
       }
       for(i=0;i<y;i++)
       {printf("*");
       }
      
       y=y+2;
       printf("\n\n");
       }
       getch();
       }

Program to Print the pyramid.

//Program to Print the pyramid.
             *
         ***
     *****
 *******

#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=1;
      for(x=3;x>=0;x--)
      {
       for(i=1;i<=x;i++)
       {printf("  ");
       }
       for(i=1;i<=y;i++)
       {printf("*");
       }
       y=y+2;
       printf("\n");
       }
       getch();
       }

Program to print the reverse pyramid of no.

//Program to print the reverse pyramid of no.
1 2 3 4 5 6 7 8 9

  1 2 3 4 5 6 7

    1 2 3 4 5

       1 2 3

          1
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i,g;
      y=9;
      for(x=4;x>=0;x--)
      {
      for(i=4;i>x;i--)
       {printf(" ");
       }g=1;
       for(i=0;i<y;i++)
       {printf("%d",g);g++;
       }
      
       y=y-2;
       printf("\n");
       }
       getch();
       }

Program to Print the pyramid.

//Print the pyramid like..
*********
  *******
   *****
     ***
       *
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=9;
      for(x=4;x>=0;x--)
      {
      for(i=4;i>x;i--)
       {printf(" ");
       }
       for(i=0;i<y;i++)
       {printf("*");
       }
      
       y=y-2;
       printf("\n");
       }
       getch();
       }

Friday, March 9, 2012

Program to print the triangle of no.

// Program to calculate the triangle of no.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
#include<conio.h>
main()
{
       int x,i;
       for(x=1;x<=5;x++)
       {
          for(i=1;i<=x;i++)
         {
                          printf("  %d",i);
          }
                          printf("\n\n");
       }
 getch();
   }

Program to Print the triangle of star.

// Program to calculate the triangle of star.





*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
main()
{
       int x,i;
       for(x=1;x<=5;x++)
       {
        for(i=1;i<=x;i++)
        {
                          printf("  *");
                          }
                          printf("\n\n");
                          }
                          getch();
                          }