0% found this document useful (0 votes)
5 views

Polynomialaddition

The document contains a C program that adds two polynomials represented by their coefficients. It prompts the user to input the sizes and coefficients of the two polynomials, then calculates the sum and displays the resulting polynomial. The program uses arrays to store coefficients and a function to handle the addition and display of the polynomial.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Polynomialaddition

The document contains a C program that adds two polynomials represented by their coefficients. It prompts the user to input the sizes and coefficients of the two polynomials, then calculates the sum and displays the resulting polynomial. The program uses arrays to store coefficients and a function to handle the addition and display of the polynomial.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<stdio.

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];
}
}

You might also like