0
2.7kviews
Write a program to display Pascal triangle.

A

AB

ABC

ABCD

ABCDE


Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 6M

Year: May 2013

1 Answer
0
48views
  • Pascal's triangle is a triangular array of the binomial coefficients.

  • The program is to display Pascal Triangle for row = 5.

Algorithm:

  • Start

  • Declare and initialize variables x, y, n, and char c.

  • Enter the number of rows.

  • Do the following operations in loop.

    • x = 1 to n

    • x++

    • assign char = A

    • y = 1 less than x

    • y++

    • print choose

    • char ++

  • Repeat the process to n.

  • Print the final required triangle.

  • Stop.

Program:

#include<stdio.h>
#include<conio.h>
int main(){
int x, y, n;
char ch;

printf("\n Enter number of Rows:");
scanf("%d",&n);

for(x = 1;x<= n;x++){
printf("\n");
ch = 'A';

for(y = 1;y<=x; y++)  {
printf("%c",ch);
ch++;
}
}
getch();
}

Output:

Enter number of Rows: 5

A

A B

A B C

A B C D

A B C D E

Please log in to add an answer.