C Online Compiler
Example: Pascal Triangle in C Program using For loop of Numbers
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Pascal Triangle in C Program using For loop of Numbers #include <stdio.h> int main() { int r, co = 1, ws, i, j; // r - To store the number of rows // co - To store the coefficient value // ws - To store the white space printf("-----Enter the number of rows to print the pattern-----\n"); scanf("%d", &r); printf("\n-----This is the pascal triangle pattern-----\n\n"); for (i = 0; i < r; i++) { printf("\t"); for (ws = 1; ws <= r - i; ws++) printf(" "); for (j = 0; j <= i; j++) { if (j == 0 || i == 0) co = 1; else co = co * (i - j + 1) / j; printf("%4d", co); } printf("\n"); } return 0; }
8
Output
Clear
ADVERTISEMENTS