Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Yang Hui\'s Triangle 121 1331 146 41 15 1010 5 1 16 15 2015 61 17 2135 35 217

ID: 3586735 • Letter: 1

Question

1. Yang Hui's Triangle 121 1331 146 41 15 1010 5 1 16 15 2015 61 17 2135 35 2171 Figure 1 Yang Huis Triangle with rows 0 through 7. A Yang Huis Triangle (also known as Pascal's Triangle) is defined as follows: 1. Row i has i + 1 elements (i starts from O). 2. Leftmost and rightmost elements (or just element in terms of the first row) are (is) always 1: Tio = Tii = 1. 3. For the other elements, TI, (for j # 0 or 6), we have: Tij = T--+ T,-, for j 0 ort 1,j1 1, Write a program to bet an input n, then calculate n rows of Yang Hui's Triangle, for is n s 100. Then print them out. Your output has to look like this: lease input the number of rows for Yang Huis Triangle : 8 1 5 10 10 5 1 1 6 15 2015 6 1 Press any key to continue Note that numbers are separated by one single space and at the end of each line there is no space Other Requirements: • Use debug techniques to supervise your result array and answer the following questions: 1. Does your program always make sense for every n in that range? If not, what's approximately the maximum in that your program can make sense with? Why? 2. Having known that, change your code to prevent it from happening.

Explanation / Answer

//copy this code u will get the o/p as it is.

#include <stdio.h>

int binomialCoeff(int n, int k);

void print(int n)

{

for (int line = 0; line < n; line++)

{

for (int i = 0; i <= line; i++)

printf("%d ", binomialCoeff(line, i));

printf(" ");

}

}

int binomialCoeff(int n, int k)

{

int res = 1;

if (k > n - k)

k = n - k;

for (int i = 0; i < k; ++i)

{

res *= (n - i);

res /= (i + 1);

}

return res;

}

int main()

{int n;

printf("enter the no of rows of yang hui's triangle:");

scanf("%d",&n);

print(n);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote