-
Notifications
You must be signed in to change notification settings - Fork 0
/
polymul
52 lines (52 loc) · 856 Bytes
/
polymul
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
struct poly
{
int coef;
int exp;
};
struct poly A[10],B[10],C[10];
void polymul();
int d1,d2;
int main()
{
int i;
printf("Enter highest degree of polynomial 1 :\n");
scanf("%d",&d1);
printf("Enter the coefficients for A:\n");
for(i=0;i<=d1;i++)
{
printf("coeff of x^ %d: \n",i);
scanf("%d",&A[i].coef);
A[i].exp=i;
}
printf("Enter highest degree of polynomial 2 :\n");
scanf("%d",&d2);
printf("Enter the coefficients for B:\n");
for(i=0;i<=d2;i++)
{
printf("coeff of x^ %d: \n",i);
scanf("%d",&B[i].coef);
B[i].exp=i;
}
polymul();
return(0);
}
void polymul()
{
int i=0,j,k;
for(j=0;j<=d1;j++)
{
for(k=0;k<=d2;k++)
{
C[i].coef=A[j].coef * B[k].coef;
C[i].exp=j+k;
i++;
}
}
printf("THE PRODUCT IS : ");
for(j=i-1;j>=0;j--)
{
printf("%dx^[%d] ", C[j].coef,C[j].exp);
}
printf("\n");
}