-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolynomial.cpp
More file actions
66 lines (66 loc) · 1.13 KB
/
Copy pathpolynomial.cpp
File metadata and controls
66 lines (66 loc) · 1.13 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#define sz 150
int main()
{
int a[sz],b[sz],c[sz],d[sz],f[2*sz]={};
printf("Enter 1st polynomial's size and them the terms\n");
int n,m;
scanf("%d",&n);
m=n;
int i=0;
while(i<n)
{
scanf("%d%d",&a[i],&b[i]);
i++;
}
i=0;
while(i<n)
{
f[b[i]]+=a[i];
i++;
}
printf("Enter 2nd polynomial's size and them the terms\n");
scanf("%d",&n);
i=0;
while(i<n)
{
scanf("%d%d",&c[i],&d[i]);
i++;
}
i=0;
while(i<n)
{
f[d[i]]+=c[i];
i++;
}
i=0;
i=sz-1;
printf("The final sum is: ");
while(i>-1)
{
if(f[i])
printf("%dx^%d ",f[i],i);
i--;
}
int ans[2*sz]={};
i=0;
int j;
while(i<m)
{
j=0;
while(j<n)
{
ans[b[i]+d[j]]+=a[i]*c[j];
j++;
}
i++;
}
printf("\nThe final Product is: ");
i=2*sz-1;
while(i>-1)
{
if(ans[i])
printf("%dx^%d ",ans[i],i);
i--;
}
}