answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<malloc.h>

int* getpoly(int);

void showpoly(int *,int);

int* addpoly(int *,int,int *,int);

int* mulpoly(int *,int,int *,int);

int main(void)

{

int *p1,*p2,*p3,d1,d2,d3;

/*get poly*/

printf("\nEnter the degree of the 1st polynomial:");

scanf("%d",&d1);

p1=getpoly(d1);

printf("\nEnter the degree of the 2nd polynomial:");

scanf("%d",&d2);

p2=getpoly(d2);

printf("Polynomials entered are\n\n");

showpoly(p1,d1);

printf("and\n\n");

showpoly(p2,d2);

/*compute the sum*/

d3=(d1>=d2?d1:d2);

p3=addpoly(p1,d1,p2,d2);

printf("Sum of the polynomials is:\n");

showpoly(p3,d3);

/*compute product*/

p3=mulpoly(p1,d1,p2,d2);

printf("Product of the polynomials is:\n");

showpoly(p3,d1+d2);

}

int* getpoly(int degree)

{

int i,*p;

p=malloc((1+degree)*sizeof(int));

for(i=0;i<=degree;i++)

{

printf("\nEnter coefficient of x^%d:",i);

scanf("%d",(p+i));

}

return(p);

}

void showpoly(int *p,int degree)

{

int i;

for(i=0;i<=degree;i++)

printf("%dx^%d + ",*(p+i),i);

printf("\b\b\b ");

printf("\n");

}

int* addpoly(int *p1,int d1,int *p2,int d2)

{

int i,degree,*p;

degree=(d1>=d2?d1:d2);

p=malloc((1+degree)*sizeof(int));

for (i=0;i<=degree;i++)

if((i>d1) && (i<=d2))

*(p+i)=*(p2+i);

else if((i>d2) && (i<=d1))

*(p+i)=*(p1+i);

else

*(p+i)=*(p1+i)+*(p2+i);

return(p);

}

int* mulpoly(int *p1,int d1,int*p2,int d2)/* this is the function of concern*/

{

int i,j,*p;

p=malloc((1+d1+d2)*sizeof(int));

for(i=0;i<=d1;i++)

for(j=0;j<=d2;j++)

p[i+j]+=p1[i]*p2[j];

return(p);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to multiply two polynomials using an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


How do you write a program in C to find and display the sum of each row and column of a 2 dimensional array of type float?

array type


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


Write a c program to find the maximum of two numbers and print out with its position?

maxValue = function (array) {mxm = array[0];for (i=0; i&lt;array.length; i++) {if (array[i]&gt;mxm) {mxm = array[i];}}return mxm;}; i don't know


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i &lt; array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.


Program to display multiplication of two matrix?

The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


How do you write a program of matrix multiplication in a simple way?

you can write by two ways 1 by giving the size of array at declaration 2 by checking condition