#include<stdio.h>
#include<conio.h>
void show(int p[]);
void main()
{
int a[10],b[10],c[10];
int n,k,i,p,coeff;
clrscr();
for(i=0;i<10;i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
}
printf("\n First polynomial");
printf("\n Enter number of terms=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter power & coefficient=");
scanf("%d%d",&p,&coeff);
a[p]=coeff;
}
printf("\n Second polynomial");
printf("\n Enter number of terms=");
scanf("%d",&k);
for(i=0;i<k;i++)
{
printf("\n Enter power & coefficient=");
scanf("%d%d",&p,&coeff);
b[p]=coeff;
}
printf("\n First polynomial is:-\n\n");
show(a);
printf("\n Second polynomial is:-\n\n");
show(b);
for(i=0;i<10;i++)
{
c[i]=a[i]+b[i];
}
printf("\n Addition of two polynomials is=\n\n");
show(c);
getch();
}
void show(int p[])
{
int i;
for(i=9;i>0;i--)
{
if(p[i]!=0)
{
printf("%dx^%d+",p[i],i);
}
}
printf("%d",p[i]);
}
#include<conio.h>
void show(int p[]);
void main()
{
int a[10],b[10],c[10];
int n,k,i,p,coeff;
clrscr();
for(i=0;i<10;i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
}
printf("\n First polynomial");
printf("\n Enter number of terms=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter power & coefficient=");
scanf("%d%d",&p,&coeff);
a[p]=coeff;
}
printf("\n Second polynomial");
printf("\n Enter number of terms=");
scanf("%d",&k);
for(i=0;i<k;i++)
{
printf("\n Enter power & coefficient=");
scanf("%d%d",&p,&coeff);
b[p]=coeff;
}
printf("\n First polynomial is:-\n\n");
show(a);
printf("\n Second polynomial is:-\n\n");
show(b);
for(i=0;i<10;i++)
{
c[i]=a[i]+b[i];
}
printf("\n Addition of two polynomials is=\n\n");
show(c);
getch();
}
void show(int p[])
{
int i;
for(i=9;i>0;i--)
{
if(p[i]!=0)
{
printf("%dx^%d+",p[i],i);
}
}
printf("%d",p[i]);
}