"program to print pascal triangle" Code Answer's

You're definitely familiar with the best coding language Java that developers use to develop their projects and they get all their queries like "program to print pascal triangle" answered properly. Developers are finding an appropriate answer about program to print pascal triangle related to the Java coding language. By visiting this online portal developers get answers concerning Java codes question like program to print pascal triangle. Enter your desired code related query in the search bar and get every piece of information about Java code related question on program to print pascal triangle. 

Java program to display pascal triangle

By Nutty NewtNutty Newt on Jan 02, 2021
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();
   }
}

Source: www.flowerbrackets.com

Add Comment

1

program to print pascal triangle

By Crazy CrocodileCrazy Crocodile on Aug 09, 2020
#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;
}

Source: www.programiz.com

Add Comment

1

All those coders who are working on the Java based application and are stuck on program to print pascal triangle can get a collection of related answers to their query. Programmers need to enter their query on program to print pascal triangle related to Java code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about program to print pascal triangle for the programmers working on Java code while coding their module. Coders are also allowed to rectify already present answers of program to print pascal triangle while working on the Java language code. Developers can add up suggestions if they deem fit any other answer relating to "program to print pascal triangle". Visit this developer's friendly online web community, CodeProZone, and get your queries like program to print pascal triangle resolved professionally and stay updated to the latest Java updates. 

Java answers related to "program to print pascal triangle"

View All Java queries

Java queries related to "program to print pascal triangle"

Browse Other Code Languages

CodeProZone