program to print pascal triangle
import java.util.Scanner;
public class PascalsTriangleJava
{
static int findFactorial(int number)
{
int factorial;
for(factorial = 1; number > 1; number)
{
factorial *= number;
}
return factorial;
}
// here's the function to display pascal's triangle
static int printPascalTraingle(int num, int p)
{
return findFactorial(num) / (findFactorial(num  p) * findFactorial(p));
}
public static void main(String[] args)
{
int row, a, b;
System.out.println("Please enter number of rows: ");
Scanner sc = new Scanner(System.in);
row = sc.nextInt();
System.out.println("Here's is pascal's triangle: ");
for(a = 0; a < row; a++)
{
for(b = 0; b < row  a; b++)
{
System.out.print(" ");
}
for(b = 0; b <= a; b++)
{
System.out.print(" " + printPascalTraingle(a, b));
}
System.out.println();
}
sc.close();
}
}
4
1
#include <stdio.h>
int main() {
int rows, coef = 1, space, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 0; i < rows; i++) {
for (space = 1; space <= rows  i; space++)
printf(" ");
for (j = 0; j <= i; j++) {
if (j == 0  i == 0)
coef = 1;
else
coef = coef * (i  j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
Thank you!
1
0
Are there any code examples left?
New code examples in category Pascal

Pascal 20220304 03:30:03 pascal special characters

Pascal 20220131 13:07:02 comment in pascal

Pascal 20211117 06:12:13 pascal comments

Pascal 20211117 01:52:17 pascal modifiers

Pascal 20211105 06:21:10 pascal cheat sheet pdf

Pascal 20211005 14:04:04 pascal cheat sheet for programmers

Pascal 20211001 18:03:02 comments in pascal

Pascal 20210929 22:08:02 Kth Row Of Pascal's Triangle

Pascal 20210920 15:21:06 pascal online compiler