C Program to print pascals triangle - c programs
//Write a c program to print pascals triangle
//Display pascals triangle in c language
//Generate pascals triangle using c
//C Program to print pascals triangle
#include<stdio.h>
#include<conio.h>
void main(){
int a[15][15],i,j,rows,num=25,k;
printf("Pascal's Triangle:");
printf("\n enter the number of rows:");
scanf("%d",&rows);
for(i=0;i<rows;i++){
for(k=num-2*i;k>=0;k--)
printf(" ");
for(j=0;j<=i;j++){
if(j==0||i==j){
a[i][j]=1;
}
else{
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
printf("%4d",a[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT:
Pascal's Triangle:
enter the number of rows:3
      1
    1 1
    1 2 1
No comments:
Post a Comment