Examples of C part 56 add 2 polynomials
Program :
Output:
Enter number of terms in Polynomial 1
5
Enter Elements of Polynomial 1
Enter x^0 Co-Efficient of Polynomial 1
1
Enter x^1 Co-Efficient of Polynomial 1
2
Enter x^2 Co-Efficient of Polynomial 1
3
Enter x^3 Co-Efficient of Polynomial 1
4
Enter x^4 Co-Efficient of Polynomial 1
5
Enter number of terms in Polynomial 2
3
Enter Elements of Polynomial 2
Enter x^0 Co-Efficient of Polynomial 2
1
Enter x^1 Co-Efficient of Polynomial 2
2
Enter x^2 Co-Efficient of Polynomial 2
33
5 x^4 + 4 x^3 + 36 x^2 + 4 x^1 + 2 x^0Explanation:
//Coming Soon..
#include<stdio.h> main() { int i,j,sizePoly[2],polynomials[2][100],maxSize=0; for(i=0;i<2;i++) { printf("Enter number of terms in Polynomial %d\n",i+1); scanf("%d",&sizePoly[i]); printf("Enter Elements of Polynomial %d\n",i+1); for(j=0;j<sizePoly[i];j++) { printf("Enter x^%d Co-Efficient of Polynomial %d\n",j,i+1); scanf("%d",&polynomials[i][j]); } if(maxSize<sizePoly[i]) maxSize=sizePoly[i]; } int sum[maxSize]; for(i=0;i<maxSize;i++) { sum[i]=0; } for(i=0;i<2;i++) { for(j=0;j<sizePoly[i];j++) { sum[j]+=polynomials[i][j]; } } for(i=maxSize-1;i>=0;i--) { if(i!=0) { printf("%d x^%d + ",sum[i],i); } else { printf("%d x^%d\n",sum[i],i); } } }
Enter number of terms in Polynomial 1
5
Enter Elements of Polynomial 1
Enter x^0 Co-Efficient of Polynomial 1
1
Enter x^1 Co-Efficient of Polynomial 1
2
Enter x^2 Co-Efficient of Polynomial 1
3
Enter x^3 Co-Efficient of Polynomial 1
4
Enter x^4 Co-Efficient of Polynomial 1
5
Enter number of terms in Polynomial 2
3
Enter Elements of Polynomial 2
Enter x^0 Co-Efficient of Polynomial 2
1
Enter x^1 Co-Efficient of Polynomial 2
2
Enter x^2 Co-Efficient of Polynomial 2
33
5 x^4 + 4 x^3 + 36 x^2 + 4 x^1 + 2 x^0Explanation:
//Coming Soon..