Q:
C++ Program to print a Pascal Triangle upto N depth
belongs to collection: Most popular and Searched C++ solved programs with Explanation and Output
Most popular and Searched C++ solved programs with Explanation and Output
- C++ program to add two integer numbers
- C++ program to add two integer numbers using function
- C++ program to add two integer numbers using pointers
- C++ program to add two integer numbers using class
- C++ program to read a string
- C++ program to display name and age
- C++ program to find factorial of a number
- C++ program to check prime number
- C++ program to display prime numbers
- C++ program to add two times
- C++ program to check EVEN or ODD
- C++ Program to find odd or even number without using modulus operator
- C++ Program to check if a number is even using Recursion
- C++ program to check leap year
- C++ program to convert lowercase character to uppercase and vice versa
- C++ program to sort an array in Ascending Order
- C++ program to sort an array in Descending Order
- C++ program to reverse a number
- C++ Program to print a Pascal Triangle upto N depth
- C++ Program to print a chessboard pattern
- C++ program to print pattern of stars till N number of rows
- C++ program to generate random alphabets and store them into a character array
- C++ program to find factorial of large numbers using array
- C++ program to find the frequency of a character in a string using Count Array
- C++ program to print a spiral matrix
- C++ program to check whether a string2 can be formed from string1
- C++ program to convert number to word (up to four digits only)
- C++ program to find the next greatest number from the same set of digits
- C++ program to find Fibonacci number using different methods
- C++ program to add seconds to the time
- C++ program to check given date is in valid format or not
- C++ program to check given string is numeric or not
- C++ program to set IP address, subnet mask, network gateway in Linux System
- C++ program to get MAC address of Linux based network device
- C++ program to set MAC address in Linux Devices
- C++ program to pad octets of IP Address with Zeros
- C++ program to set network settings for IPv6 Network in Linux Devices
- C++ program to find total number of days in given month of year
- C++ program to get previous date of given date
- Reading date and time from Linux operating system using C++ program
- Set date and time in Linux Operating System using C++ program
- C++ program to get week day from given date
- Find last index of a character in a string using C++ program
- C++ program to print the maximum possible time using six of nine given single digits
- Sieve of Eratosthenes to find prime numbers using c++
- C++ program to print your name randomly on the screen with colored text
- C++ program to demonstrate example of delay() function
- Example of declaring and printing different constants in C++
- How to skip some of the array elements in C++?
- C++ program to keep calculate the sum of the digits of a number until the number is a single digit
- C++ Program to print right angled pyramid of numbers
- C++ program to print right angled (Right oriented) pyramid of numbers
- C++ program to print Hello World/First Program in C++
- Read character array as string using cin in C++
- C++ program to demonstrate example of cascading cout and cin
- C++ program to demonstrate use of Scope Resolution Operator
- C++ program to demonstrate use of reference variable
- C++ program to use function as a LVALUE using reference variable
- C++ program to demonstrate example of Inline Function
- C++ program to demonstrate example of Default Argument
- C++ program to demonstrate methods of passing arguments in function:
- C++ program to demonstrate example of function overloading
- C++ program to read string using cin.getline()
- C++ program to generate random numbers
- Print Reverse Triangle Bridge Pattern for Characters in C++
Program to print Pascal Triangle in C++
Output
In this program, first of all we are checking if user enters a valid height. If h is less than 1, that means either 0 or negative, we can’t form the pascal triangle.
Then, we are taking two loops, one to control rows (outer loop or the i loop) and other to control columns (the j loop). The digit variable will hold the value to be printed. In the first if statement, we are placing 1 at the first column of every row.
In the else part, we are simply multiplying the digit variable with a small math logic. The (i-j+1)/j calculates the relative position.
need an explanation for this answer? contact us directly to get an explanation for this answer