Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When we want to multiply two polynomials in algebra, we expand it the following way: (4x + 3) ? 2x 3 + 5x + 9

When we want to multiply two polynomials in algebra, we expand it the following way: (4x + 3) ? 2x 3 + 5x + 9 ? = 4x ? 2x 3 + 5x + 9 ? + 3 ? 2x 3 + 5x + 9 ? = 8x 4 + 20x 2 + 36x + 6x 3 + 15x + 27 = 8x 4 + 6x 3 + 20x 2 + 51x + 27 In the above example, we could represent the coefficients in array form as [3,4] and [9,5,0,2], i.e, in increasing order of degree from left to right. Write a program that takes the array-forms of the integer coefficients of two polynomials and computes the coefficients of the resulting polynomial (after multiplication) (in the same format as above). Answer format: (a) polymult.c #include #include #include #include int main(){ int n1; //Degree of the first polynomial + 1 int n2; //Degree of the second polynomial + 1 int n3; //Degree of product int i; scanf("%d", &n1); scanf("%d", &n2); int * a = malloc(n1*sizeof(int)); //First polynomial int * b = malloc(n2*sizeof(int)); //Second polynomial for(i=0; i scanf("%d", &a[i]); } for(i=0; i scanf("%d", &b[i]); } //Your code here //set n3 as the size of output array //Output array should be c. Initialise as the following: //int * c = malloc(n3*sizeof(int)); for(i=0; i printf("%d ", c[i]); } return 0; } (b) polymult.py n1 = int(input()) #Degree of the first polynomial + 1 n2 = int(input()) #Degree of the second polynomial + 1 a = [ ] #First polynomial b = [ ] #Second polynomial for i in range(n1): a.append(int(input())) for i in range(n2): b.append(int(input())) #Your code here #Set n3 as the size of output array #Output array should be c for i in range(n3): print(c[i])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Describe the benefits of employee orientation.

Answered: 1 week ago

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago