Turn Desktop View Off
by Dinesh Thakur

In this program to Print the Pascal Triangle Two core concepts will be on the trot. The Control statement (if-else), and Loop Statements. There in the program Integer type Variables declare which use to contain the value. Here variable i,j and Num will use in the Loop statement as according the requirement. As required in the program Nested Loop used for fulfilling the condition along within the control Statement.

In the Program to print Triangle the loop Statement will be used many times like nested Loop Statement. As shown in The Program value entered in condition place and with the if condition used either condition gets true will be print desired row or else part will be followed to print in else condition the calculation will be manipulated for getting the correct output.


Problem Statement:-
Pascal Triangle Which we might have studied in Binomial Theorem here we Print Pascal Triangle. With the use of Loop Statement and Control statement. Write a program to read the data and determine the following:
  1. Entering the Number for Triangle.
  2. Using loop Statement.
  3. Using Control Statement for condition.
  4. Display output on the Screen.

This C program is successfully compiled and run on a System. Output is shown below.


#include<stdio.h>

#include<conio.h>
void main()
{
            int i=1,j,num,x=1;
            clrscr();
            printf("Please Enter the Number :");
            scanf("%d",&num);
            printf("\n\n");
            printf("OUTPUT:\n");
            printf("------");
            printf("\n\n");
            printf("The Pascal Triangle is \n");
            printf("**********************\n");
            for(i=1;i<=num;i++)
                 {
                    for(j=1;j<=i;j++)
                        {
                            if(j==1)
                              {
                                     x=1;
                                     printf("%d",x);
                               }
                            else
                              {
                                     x=(x*(i-j+1)/(j-1));
                                     printf("%d",x);
                               }
                       }
                                     printf("\n");
                }
                                     getch();
}
 

Print a Pascal Triangle