I am trying to output a left-justified Pascal’s triangle. The program should first read one positive integer N from the user via a prompt “N:”. Then, the program will print the first N rows of the Pascal’s triangle on the screen. However, I think that there is a problem with my outer two for-loops. Instead of getting (N=3)
1
1,1
1,2,1
I am getting
1
1,2
2,4,4
#include <stdio.h>
int main(void) {
int input,i,j,k,p,N,x;
int f1=1;
int f2=1;
int f3 = 1;
printf("N:");
scanf("%d",&N);
for(i=1;i<=N;i++){
for(j=1;j<=i;j++){
for(x = 1; x<= N-1; x++){
f1 = f1 * x;
}
for(x = 1; x <= j-1; x++){
f2 = f2 * x;
}
for(x = 1; x <= N-j; x++){
f3 = f3 * x;
}
p= (f1)/(f2*f3);
if(j==i)
printf("%d",p);
else
printf("%d,",p);
}
printf("\n");
}
return 0;
}