Polynomialaddition
Polynomialaddition
h>
void add(int[],int [],int size,int,int);
void display(int size);
int c[20];
void main(){
int i,size1,size2,a[20],b[20],size;
printf("Enter the Size of the first polynomial(Highest degree of the
polynomial)");
scanf("%d",&size1);
printf("Enter the coefficients of the polynomial starting from the highest
degree");
for(int i=size1;i>=0;i--){
scanf("%d",&a[i]);
}
printf("Enter the Size of the second polynomial(Highest degree of the
polynomial)");
scanf("%d",&size2);
printf("Enter the coefficients of the polynomial starting from the highest
degree");
for(int i=size2;i>=0;i--){
scanf("%d",&b[i]);
}
if(size1<size2){
size=size2;
}
else{
size=size1;
}
add(a,b,size,size1,size2);
display(size);
}
void display(int size){
for(int i=size;i>=0;i--){
printf("%dx^(%d)+",c[i],i);
}
printf("\b");
}
void add(int a[],int b[],int size,int size1,int size2){
for(int i=0;i<=size;i++){
if(i<=size1)
c[i]=c[i]+a[i];
if(i<=size2)
c[i]=c[i]+b[i];
}
}