#include#include void init(int []); void accept(int [],int); void accept1(int [],int); void display(int [],int); void display1(int [],int); void add(int [],int [],int [],int); void main() { int a[10],b[10],c[10],t1,t2,t3; clrscr(); init(a); init(b); printf("\n Enter The Degree of Polynomial1 : "); scanf("%d",&t1); printf("\n Enter The Order of Polynomial1 \n"); accept(a,t1); printf("\n Enter The Degree of Polynomial2 : "); scanf("%d",&t2); printf("\n Enter The Degree of Polynomial2 \n"); accept1(b,t2); printf("\n The Polynomial 1 is : "); display(a,t1); printf("\n The Polynomial 2 is : "); display1(b,t2); t3=t1>t2?t1:t2; printf("\n Addition is: "); add(a,b,c,t3); getch(); } void init(int p[]) { int i; for(i=0;i<10;i++) { p[i]=0; } } void accept(int a[],int t1) { int i; for(i=t1;i>=0;i--) { printf("\n Enter The Coeff of X^%d : ",i); scanf("%d",&a[i]); } } void accept1(int b[],int t2) { int i; for(i=t2;i>=0;i--) { printf("\n Enter The Coeff of X^%d : ",i); scanf("%d",&b[i]); } } void display(int a[], int t1) { int i; for(i=t1;i>0;i--) { printf("%dX%d + ",a[i],i); } printf("%dX%d",a[i],i); } void display1(int b[], int t2) { int i; for(i=t2;i>0;i--) { printf("%dX%d + ",b[i],i); } printf("%dX%d",b[i],i); } void add( int a[],int b[],int c[], int t3) { int i; for(i=t3;i>=0;i--) { c[i]=a[i]+b[i]; } for(i=t3;i>0;i--) { printf("%dX%d + ",c[i],i); } printf("%dX%d",c[i],i); } /*OUTPUT Enter The Degree of Polynomial1 : 3 Enter The Order of Polynomial1 Enter The Coeff of X^3 : 3 Enter The Coeff of X^2 : 5 Enter The Coeff of X^1 : 7 Enter The Coeff of X^0 : 1 Enter The Degree of Polynomial2 : 2 Enter The Degree of Polynomial2 Enter The Coeff of X^2 : 4 Enter The Coeff of X^1 : 8 Enter The Coeff of X^0 : 9 The Polynomial 1 is : 3X3 + 5X2 + 7X1 + 1X0 The Polynomial 2 is : 4X2 + 8X1 + 9X0 Addition is: 3X3 + 9X2 + 15X1 + 10X0 */
Write a 'C' Program to read two polynomials, add them and display the result using array.
Reviewed by
on
November 16, 2013
Rating: