-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyar.c
73 lines (66 loc) · 1.35 KB
/
polyar.c
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
67
68
69
70
71
72
73
#include<stdio.h>
#include<stdlib.h>
void createp(int arr[],int n)
{
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}
int max(int a,int b)
{
if(a>b)
return a;
return b;
}
int min(int a,int b)
{
if(a<b)
return a;
return b;
}
void viewpolynomial(int P[],int n)
{
int i;
for(int i=n;i>=0;i--)
{
printf("%dx^%d",P[i],i);
if (i!=0)
printf("+ ");
else
printf("\n");
}
}
void addpoly(int P1[],int n1,int P2[],int n2,int P[])
{
int sn=min(n1,n2);
int i=0;
for(i=0;i<=sn;i++)
P[i]=P1[i]+P2[i];
for(i=sn+1;i<=n1;i++)
P[i]=P1[i];
for(i=sn+1;i<=n2;i++)
P[i]=P2[i];
viewpolynomial(P,max(n1,n2));
return;
}
void main()
{
int i,j,P1[5],P2[5],P[5],n1,n2;
printf("Enter the degree of the first polynomial\n");
scanf("%d",&n1);
printf("Enter the terms in the order of their decreasing degree\n");
for(i=n1;i>=0;i--)
scanf("%d",&P1[i]);
printf("\n\n");
printf("\nEnter the degree of the second polynomial\n");
scanf("%d",&n2);
printf("Enter the terms in the order of their decreasing degree\n");
for(j=n2;j>=0;j--)
scanf("%d",&P2[j]);
printf("\n");
viewpolynomial(P1,n1);
viewpolynomial(P2,n2);
printf("\nResultant polynomial is: \n");
addpoly(P1,n1,P2,n2,P);
}