C program to print triangle.Pascal's triangle,pyramid - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Monday, December 23, 2019

C program to print triangle.Pascal's triangle,pyramid - My CS Tutorial

C program code to print or create a Pascal's triangle.
In this tutorial we will learn how to write a c program to create or print Pascal's triangle.


C program code


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    int a,b,c,rows,count;
    long z;
    printf("\n Enter number of rows:\n ");
    scanf("%d",&rows);
    count=rows-1;
    for(a=0;a<rows;a++)
    {
        z=1;
        for(c=0;c<=count;c++)
        {
            printf("   ");
        }
          for(b=0;b<=a;b++)
        {
            printf("%6ld",z);
            z=(z*(a-b)/(b+1));
        }
        count--;
        printf("\n");
    }
    getch();
}


OUTPUT:





In this output we can see that this is a Pascals triangle. In the first we will enter the range or number of rows of pascal triangle then triangle will be print.
In this output the value of rows is 7.

Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment