#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void accept_poly(int b[], int m)
{
int i;
for(i=m-1; i>=0; i--)
{
printf("Enter coefficent of x[%d] term: ",i);
scanf("%d",&b[i]);
}
}
void disp_poly(int b[], int n)
{
int i;
for(i=n-1; i>=0; i--)
{
if(b[i]>0)
printf("+%dx^%d",b[i],i);
else if(b[i]<0)
Name:
Class:
Roll No:
printf("%dx^%d",b[i],i);
}
printf("\n");
}
void add_poly(int a[], int b[], int c[], int n)
{
int i;
for(i=n-1; i>=0; i--)
c[i] = a[i] + b[i];
}
void main()
{
int a[10]={0},b[10]={0},c[10]={0},m,n,p;
printf("Enter order of polynomial 1: ");
scanf("%d",&m);
accept_poly(a,m);
printf("Enter order of polynomial 2: ");
scanf("%d",&n);
accept_poly(b,n);
printf("Polynomial1: ");
disp_poly(a,m);
printf("Polynomial2: ");
disp_poly(b,n);
printf("Polynomial3: ");
p = m>n ? m : n;
add_poly(a,b,c,p);
disp_poly(c,p);
getch();
}
Output-
Enter order of polynomial 1: 3
Enter coefficent of x[2] term: 4
Enter coefficent of x[1] term: 2
Enter coefficent of x[0] term: 3
Enter order of polynomial 2: 3
Enter coefficent of x[2] term: 3
Enter coefficent of x[1] term: 4
Enter coefficent of x[0] term: 4
Polynomial1: +4x^2+2x^1+3x^0
Polynomial2: +3x^2+4x^1+4x^0
Polynomial3: +7x^2+6x^1+7x^0
/
Recent Posts
Posted on 2019-07-18
Posted on 2019-07-18
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-07-17
Posted on 2019-05-28
Posted on 2019-05-24
Posted on 2019-05-24
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23
Posted on 2019-05-23