## Write a program to store two polynomials in array and print the subtraction of the polynomials

/*
PROGRAM 8:
———-
Write a program to store two polynomials in array and print the
subtraction of the polynomials.
*/
#include<stdio.h>
#include<conio.h>

void main()
{
int a[10]={0},b[10]={0},c[10]={0},md1,md2,i,md;
clrscr();

printf(“Enter the highest degree of Polynomial1==> “);
scanf(“%d”,&md1);

for(i=md1;i>=0;i–)
{
printf(“Enter the co-efficient of X^%d: “,i);
scanf(“%d”,&a[i]);
}
printf(“\nEnter the highest degree of Polynomial2==> “);
scanf(“%d”,&md2);

for(i=md2;i>=0;i–)
{
printf(“Enter the co-efficient of X^%d: “,i);
scanf(“%d”,&b[i]);
}
if(md1>md2)
md=md1;
else
md=md2;
for(i=md;i>=0;i–)
{
c[i]=a[i]-b[i];
}
printf(“\n\nResultant Polynomial After Subtraction is: \n\n”);
for(i=md;i>=0;i–)
{
if(i==md)
printf(“%dX^%d”,c[i],i);
else if(c[i]>=0)
{
printf(“+%dX^%d”,c[i],i);
}
else
printf(“%dX^%d”,c[i],i);
}

getch();
}
/*
OUTPUT:
——-
Enter the highest degree of Polynomial1==> 3
Enter the co-efficient of X^3: 4
Enter the co-efficient of X^2: 3
Enter the co-efficient of X^1: 0
Enter the co-efficient of X^0: 2

Enter the highest degree of Polynomial2==> 2
Enter the co-efficient of X^2: 3
Enter the co-efficient of X^1: -1
Enter the co-efficient of X^0: 1
Resultant Polynomial After Subtraction is:

4X^3+0X^2-1X^1+1X^0
*/