/* Write a C program to construct a pyramid of numbers. */



#include<stdio.h>

#include<conio.h>



void main()

{

int num,i,y,x=35;

clrscr();

printf("nEnter the number to generate the pyramid:n");

scanf("%d",&num);



for(y=0;y<=num;y++)

{

    /*(x-coordinate,y-coordinate)*/

    gotoxy(x,y+1);



    /*for displaying digits towards the left and right of zero*/

    for(i=0-y;i<=y;i++)



    printf("%3d",abs(i));

    x=x-3;

}

getch();
}

/* Write a C program to generate Pascal's triangle. */



#include<stdio.h>

#include<conio.h>



void main()

{

int bin,p,q,r,x;

clrscr();

bin=1;

q=0;



printf("Rows you want to input:");

scanf("%d",&r);



printf("nPascal's Triangle:n");



while(q<r)

{

    for(p=40-3*q;p>0;--p)

    printf(" ");

    for(x=0;x<=q;++x)

    {
if((x==0)||(q==0))

         bin=1;

        else

         bin=(bin*(q-x+1))/x;

         printf("%6d",bin);

    }



printf("n");

++q;

}

getch();

}

week-8x

  • 1.
    /* Write aC program to construct a pyramid of numbers. */ #include<stdio.h> #include<conio.h> void main() { int num,i,y,x=35; clrscr(); printf("nEnter the number to generate the pyramid:n"); scanf("%d",&num); for(y=0;y<=num;y++) { /*(x-coordinate,y-coordinate)*/ gotoxy(x,y+1); /*for displaying digits towards the left and right of zero*/ for(i=0-y;i<=y;i++) printf("%3d",abs(i)); x=x-3; } getch();
  • 2.
    } /* Write aC program to generate Pascal's triangle. */ #include<stdio.h> #include<conio.h> void main() { int bin,p,q,r,x; clrscr(); bin=1; q=0; printf("Rows you want to input:"); scanf("%d",&r); printf("nPascal's Triangle:n"); while(q<r) { for(p=40-3*q;p>0;--p) printf(" "); for(x=0;x<=q;++x) {
  • 3.
    if((x==0)||(q==0)) bin=1; else bin=(bin*(q-x+1))/x; printf("%6d",bin); } printf("n"); ++q; } getch(); }