The output should be like this Question 4 *Write a recursive function Binomial t
ID: 3669741 • Letter: T
Question
The output should be like this Question 4 *Write a recursive function Binomial that takes in two non- negative integers nN and nK with nK between 0 and nN, and returns the binomial coefficient (n). The binomial coefficient can be written as kk-1 k with andn both defined to be 1. with ) andn *Write a program that prompts the user for a positive integer cRows. *It should then use for loops and your Binomial function to print out Pascal's triangle, where, assuming the first row is row O and the first column is column 0, the entry in the n^th row and k4th column of the triangle is given by (n) ECE 114 Lab 7- Searching and Sorting, Recursion 7Explanation / Answer
#include <iostream>
using namespace std;
void PascalsTriangle(int);
int main()
{
int n;
cout << "Enter the number of rows you would like to print for Pascal's Triangle: ";
cin >> n;
if(n!=0 && n!=-1)
{
PascalsTriangle(n);
}
else
{
cout << "Invalid Entry"<< endl;
cout << "Enter the number of rows you would like to print for Pascal's Triangle: ";
cin >> n;
PascalsTriangle(n);
}
return 0;
}
void PascalsTriangle (int n){
int i,j,x;
for(i=0;i<n;i++)
{
x=1;
for(j=0;j<=i;j++)
{
cout << x << " ";
x = x * (i - j) / (j + 1);
}
cout << endl;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.