C program to print Pascal triangle using For Loop

By | 25.11.2016

Print Pascal triangle using For Loop


Write a C program to print Pascal triangle using For Loop. Here’s simple C program to print Pascal triangle using For Loop in C Programming Language.


Here is source code of the C program to print Pascal triangle using For Loop. The C program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C program to print Pascal triangle using For Loop  */

#include<stdio.h>
 
long fact(int);
int main(){
    int line,i,j;
 
    printf("Enter the no. of lines: ");
    scanf("%d",&line);
 
    for(i=0;i<line;i++){
         for(j=0;j<line-i-1;j++)
             printf(" ");
 
         for(j=0;j<=i;j++)
             printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
         printf("\n");
    }
    return 0;
}
 
long fact(int num){
    long f=1;
    int i=1;
    while(i<=num){
         f=f*i;
         i++;
  }
  return f;
 }

Output :


/*  C program to print Pascal triangle using For Loop  */

Enter the no. of lines: 8

       1
      1 1
     1 2 1
    1 3 3 1
   1 4 6 4 1
  1 5 10 10 5 1
 1 6 15 20 15 6 1
1 7 21 35 35 21 7 1

Process returned 0

Above is the source code for C program to print Pascal’s triangle using For Loop which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

5 1 vote
Article Rating
Category: C Programming Pattern Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments