Pascal Triangle Program In Php

Pascal Triangle Program In Php Average ratng: 3,7/5 473votes

Program Output: Explanation: 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.

Design Of Liquid Retaining Concrete Structures Pdf Printer. 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', 'n' 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'. After that a for-loop has to be implemented where counter variable I wil start from 0 till n-1. Inside this for loop there will be another for loop where its counter variable 'c' will start from 0 till (n-i-2).

The statement printf(' ') wll place blank gap and another for is used which will calculate and display the value of factorial(i)/ (factorial(c)*factorial(i-c)). The next printf(' n') statement is used to go to the next line.

Pascal Triangle Program In Php

In Pascal triangle, the first and the second rows are set to 1. Each element of the triangle (from the third row downward) is the sum of the element directly above it and the element to the left of the element directly above it.

The return 0; statement is used to return an integer type value back to main(). Now, within the factorial() function definition, an integer variable 'c' is declared and another variable name result of type long is also declared and initialized with value '1'. Now a for loop is implemented where counter variable 'c' starts from 1 till n and accordingly the value of result*c gets stored in result and gets returned. Canon Vixia Hr300 Manual Treadmill here.

Comments are closed.