program to print pascal triangle

Solutions on MaxInterview for program to print pascal triangle by the best coders in the world

showing results for - "program to print pascal triangle"
Christian
11 Jun 2020
1#include <stdio.h>
2int main() {
3   int rows, coef = 1, space, i, j;
4   printf("Enter the number of rows: ");
5   scanf("%d", &rows);
6   for (i = 0; i < rows; i++) {
7      for (space = 1; space <= rows - i; space++)
8         printf("  ");
9      for (j = 0; j <= i; j++) {
10         if (j == 0 || i == 0)
11            coef = 1;
12         else
13            coef = coef * (i - j + 1) / j;
14         printf("%4d", coef);
15      }
16      printf("\n");
17   }
18   return 0;
19}
20
Nico
14 Jan 2018
1import java.util.Scanner;
2public class PascalsTriangleJava 
3{
4   static int findFactorial(int number)
5   {
6      int factorial;
7      for(factorial = 1; number > 1; number--)
8      {
9         factorial *= number;
10      }
11      return factorial;
12   }
13   // here's the function to display pascal's triangle
14   static int printPascalTraingle(int num, int p) 
15   {
16      return findFactorial(num) / (findFactorial(num - p) * findFactorial(p));
17   }
18   public static void main(String[] args) 
19   {
20      int row, a, b;
21      System.out.println("Please enter number of rows: ");
22      Scanner sc = new Scanner(System.in);
23      row = sc.nextInt();
24      System.out.println("Here's is pascal's triangle: ");
25      for(a = 0; a < row; a++) 
26      {
27         for(b = 0; b < row - a; b++)
28         {
29            System.out.print(" ");
30         }
31         for(b = 0; b <= a; b++)
32         {
33            System.out.print(" " + printPascalTraingle(a, b));
34         }
35         System.out.println();
36      }
37      sc.close();
38   }
39}
queries leading to this page
program to find the total of pascal triangle in cpascal triangle pattern program in javapascal 27s triangle in javaprint pascal triangle in schemepyramid structure by using cjava pascal trianglefull inverted pyramid using 2a in chow to program pascal 27s trianglewrite a program to print pascal 27s triangle for a given number of rows code for pascal triangleall pascal 27s triangle pattern javapascal triangle codehow to solve pascal triangle in javafastest way to print pascals triangle c 2b 2bgiven an integer n 2c print the corresponding inverted full pyramid pattern for n for example if n 3d 5 then pattern will be like 3a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a c program to print pascal 27s trianglepascal triangle c programpascal triangle print pascal triangle in cprocedural loop pyramudprint pascal 27s triangleprinting pascal triangle in javahow to print triangle using cpascal 27s triangle iipascal triangle c codehow to print right triangle using cpascal triangle java programtriange cprint pascal trianglepascal 27s triangle in cpascal triangle left in javajava code to print pascal 27s trianglec programs pyramidwrite a function which prints the pascal 27s triangle as shown below 3ahow to code pascal triangle in chow to print pascal triangle in c 2b 2bjava program to display pascal trianglehow to make pascal triangle in c using whiuleprint pascals triangle schemepascal triangle in javapascal 27s triangle javapascal triangle javapascal 27s triangle java programhow to create pascal 27s triangle in javapascal triangletriangel logic in cprinting patterns in chow to print ascals triangelein cpascal triangle logic javahow to make pascal triangle in c using while loophow to print a pyramid in cprintf triangle a in cprinting patternc code for floyed pyramidpascal 27s trianglepascal triangle c write a c program to print pascal trianglepattern printing in cprint pascal number trianglepascal triangle pattern in chow to make a pascal triangle in javahow to make pascal 27s triangle in javawrite a program to print pascal triangle incprint rom pyramidhow to make pascal 27s triangle using cc pascals triangleprint pascal triangle in cc program for pyramid of starstriangle in cprint pascal triangle in c 2b 2bpyramid printing in cwrite a program to print pascal 27s trianglepattern program in ctriangle programs in chow to print pascal triangle in cpatterns in cwrite a program to print pascal triangle in cprint a pascal 27s triangleprogram to print the pascal triangle in cpppascals triangle in javac print pascals trianglepascal 27s triangle program in javaprint pascal 27s triangle schemeprint pascal triangle in cpppascal triangle formula javawrite a c program to print pascal triangle for a given numberpattern design in cprogram to print pascal triangleprint pascal triangle gfg practicejava pascal triangle programjava program to print pascal trianglepascal 27s triangle solution javaprint triangles in cgenerate pascal 27s triangle javapascal triangle code in javapascal triangle program in cprintf triangle in chow to print a pascal s triangle in cpascal triangle using cpascal 27s triangle code in javawrite a java program to display pascal 27s trianglewrite a program to print pascal triangle write ac program to display pascal 27s trianglepascal 27s triangle java codeprogram to print pascal triangle