Pascal Triangle in C
Here we will see how to write a program to print Pascal Triangle in C language without using any function.
Program to print Pascal triangle in C
#include <stdio.h> #include <conio.h> int main() { int row, col, space, n, totalrows; printf("Wecome to https://bptutorials.com \n"); printf("Enter no. of rows you want in Pascal Triangle:"); scanf("%d", &totalrows); for(row=0; row < totalrows; row++) { for(space=0; space < totalrows - row; space++) { printf(" "); } // for print both side outer 1 n = 1; for(col=0; col <= row; col++) { printf("%d ", n); // main logic of program n = n * (row - col) / (col +1); } printf("\n"); } getch(); }
Output :
