Header Ads

Pascal Triangle Using Alphabets

Write a program to create the following Pyramid using C program?
                   A
          A B
        A B C
       A B C D
     A B C D E
   A B C D E F

This program will create a pattern which consists of the Pascal triangle. So first of all, you have to include the stdio header file using the "include" preceding by # which tells that the header file needs to be process before compilation, hence named preprocessor directive. A long type user defined function prototype name - "factorial()" is being taken with parameter type as integer.
Then you have to define the main() function and it has been declared as integer so by default it returns integer. Inside the main() function you have to declare three integer type variable name - 'i', 'm' and 'c'. Then a printf() function is used which will prints the message - "How many rows you want to show in pascal triangle?" Then the scanf() function is used to fetch the data from the user and store it in 'n'.


***************************Program***********************

#include < stdio.h > #include < conio.h >
  main() {
    int r, c, k, m, i;
    printf("Enter the number of lines : ");
    scanf("%d", & m);
    for (r = 1; r <= m; r++) {
      i = 0;
      for (c = 1; c <= m - r; c++) {
        printf(" ");
      }
      for (k = 1; k <= r; k++) {
        printf("%c ", 65 + i);
        i++;
      }
      printf("\n");
    }
    getch();
    return 0;
  }


***************************Output*************************


screen shot for pascal triangle using alphabet

No comments