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
Ryan Reich 105 points

                                    #include &lt;stdio.h&gt;
int main() {
   int rows, coef = 1, space, i, j;
   printf(&quot;Enter the number of rows: &quot;);
   scanf(&quot;%d&quot;, &amp;rows);
   for (i = 0; i &lt; rows; i++) {
      for (space = 1; space &lt;= rows - i; space++)
         printf(&quot;  &quot;);
      for (j = 0; j &lt;= i; j++) {
         if (j == 0 || i == 0)
            coef = 1;
         else
            coef = coef * (i - j + 1) / j;
         printf(&quot;%4d&quot;, coef);
      }
      printf(&quot;\n&quot;);
   }
   return 0;
}

4 (1 Votes)
0
Are there any code examples left?
New code examples in category Pascal
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
print pascal triangle gfg practice java pascal triangle pascal's triangle code in java Printing Pascal Triangle in Java fastest way to print pascals triangle c++ print a pascal's triangle Write a program to print Pascal triangle. Pascal's Triangle solution java Write ac program to display Pascal's triangle how to print pascal triangle in c++ pascal triangle code in java all pascal's triangle pattern java write a program to print pascal triangle inc generate pascal's triangle java pascal's triangle in java pascals triangle in java write a program to print pascal's triangle how to make a pascal triangle in java pascal's triangle program in java java program to print pascal triangle pascal triangle in java write a c program to print pascal triangle write a java program to display pascal's triangle pascal's triangle java how to create Pascal's Triangle in java java pascal triangle program print Pascal Number Triangle Write a function which prints the Pascal's triangle as shown below: how to solve pascal triangle in java how to make pascal's triangle in java pascal's triangle java code print pascal triangle in scheme print pascal's triangle scheme print pascals triangle scheme pascal triangle java pascal triangle c how to make pascal triangle in c using while loop how to make pascal triangle in c using whiule how to make pascal's triangle using C c program for pyramid of stars Pascal's Triangle II pascal triangle pascal's triangle Write a program to print pascal's triangle for a given number of rows. pyramid structure by using c how to print ascals triangelein c pascal triangle c program pattern printing in c pattern design in c Java program to display pascal triangle c programs pyramid pyramid printing in c pattern program in c print rom pyramid triangle programs in C printing patterns in c triange c triangel logic in c Given an integer N, print the corresponding Inverted Full Pyramid pattern for N. For example if N = 5 then pattern will be like: * * * * * * * * * * * * * * * patterns in c full inverted pyramid using * in c how to print a pyramid in c c code for floyed pyramid code for pascal triangle printing pattern how to program pascal's triangle c print pascals triangle c pascals triangle program to find the total of pascal triangle in c Write a C program to print pascal triangle for a given number pascal's triangle in c pascal triangle in c pascal triangle using c program to print pascal triangle pascal triangle code print pascal's triangle procedural loop pyramud pascal triangle pattern in c print pascal triangle in c how to print a pascal s triangle in C how to code pascal triangle in c pascal triangle program in c triangle in c print pascal triangle pascal triangle print pascal triangle c code
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source