Pascal Triangle.
#include<stdio.h>
int main() {
int c=1,n;
printf("Enter a number : ");
scanf("%d",&n);
for (int i=0; i<n; i++){
for (int j=1; j<=n-i; j++){
printf(" ");
}
for (int j=0; j<=i; j++){
if (i==0 || j==0){
c=1;
}
else{
c=c*(i-j+1)/j;
}
printf(" %d",c);
}
printf("\n");
}
return 0;
}
Output:-
Enter a number : 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
No comments:
Post a Comment