Archive for the ‘Printing Pyramids’ Category

Pascal’s Triangle

Posted: September 20, 2011 by Mayur More in Printing Pyramids


 

 

 

 

 

 

CLICK TO KNOW MORE ABOUT PASCAL’S TRIANGLE:

 

CODE:

#include<stdio.h>
#include<conio.h>
#include<math.h>
 
long factorial(int);
 
main()
{
   int i, n, c,k;
 
   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);
   k=n;
 
   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c<=k-2  ; c++ )
	 printf(" ");
	 printf("%d",c);

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
 
      printf("\n");
      k--;
   }
 
   getch();
   return 0;
}
 
long factorial(int n)
{
   int c;
   long result = 1;
 
   for( c = 1 ; c <= n ; c++ )
         result = result*c;
 
   return ( result );
}

 

Program to print the following pyramids:

Posted: August 27, 2011 by Mayur More in Printing Pyramids
*********
****_****
***___***
**_____**
*_______*

 

#include<stdio.h>
#include<conio.h>
void main()
{
         int i,j,x=0,c;
         for(i=5;i>=1;i--)
         {
                   for(j=1;j<=i;j++)
                    {
                      printf("*");
                     }
                     for(c=(2x-1);c>=1;c--)
                    {
                      printf(" ");
                     }

                   for(j=i;j>=1;j--)
                   {
                              if(j!=5)
                              {
                               printf("*");
                              }
                    }
                   x++;

                     printf("\n");
          }
getch();
}


Program to print the following pyramid:

Posted: August 27, 2011 by Mayur More in Printing Pyramids
123454321
1234_4321
123___321
12_____21
1_______1

(more…)

program to print the following pyramid:

Posted: August 27, 2011 by Mayur More in Printing Pyramids
1234554321
1234__4321
123____321
12______21
1________1
  

#include<stdio.h>
#include<conio.h>
void main()
{
         int i,j,x=0,c;
         for(i=5;i>=1;i--)
         {
                   for(j=1;j<=i;j++)
                    {
                      printf("%d",j);
                     }
                     for(c=2x;c>=1;c--)
                    {
                      printf(" ");
                     }

                   for(j=i;j>=1;j--)
                   {
                      printf("%d",j);
                    }
                   x++;

                     printf("\n");
          }   
getch();
}

Program to print the following pyramid:

Posted: August 27, 2011 by Mayur More in Printing Pyramids
____1 
___121 
__12321 
_1234321 
123454321

 

#include<stdio.h>
#include<conio.h>
void main()
{
   int i, j, x=7,num=1;
   for(i=1;i<=5;i++)
   {
           for(j=1;j<=x;j++)
           {
                    printf(" ");
            }
           for(j=1;j<=i;j++)
           {
                    printf("%d",num);
                    num++;
            }
            num--;
            for(j=1;j<=(i-1);j++)
            {
                     num--;
                     printf("%d",num);
             }
             num=1;
             printf("\n");
             x--;

    }

}


Program to Print the following Pyramid

Posted: August 27, 2011 by Mayur More in Printing Pyramids
12345
1234
123
12
1

#include<stdio.h>
#include<conio.h>

void main()

{

         int i,j;

         for(i=1;i<=5;i++)

         {

                   for(j=1;j<=5;j++)

                   {

                          printf("%d",j);

                    }

          printf("\n");

          }   

getch();

}