Examples of C part 58 add n Polynomial
Program :
Output:
Explanation:
//Coming Soon..
#include<stdio.h> main() { int i,j,totPolynomials,maxSize=0; printf("Enter Number of Polynomials to add\n"); scanf("%d",&totPolynomials); int polynomials[totPolynomials][100],eachPolynomialSize[totPolynomials]; for(i=0;i<totPolynomials;i++) { printf("Enter Size of %d Polynomial\n",i+1); scanf("%d",&eachPolynomialSize[i]); if(maxSize<eachPolynomialSize[i]) maxSize=eachPolynomialSize[i]; for(j=0;j<eachPolynomialSize[i];j++) { printf("Enter x^%d Co-Efficient of %dth Polynomial\n",j,i); scanf("%d",&polynomials[i][j]); } } int sum[maxSize]; for(i=0;i<maxSize;i++) { sum[i]=0; } for(i=0;i<totPolynomials;i++) { for(j=0;j<eachPolynomialSize[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 Polynomials to add 4 Enter Size of 1 Polynomial 3 Enter x^0 Co-Efficient of 0th Polynomial 2 Enter x^1 Co-Efficient of 0th Polynomial 3 Enter x^2 Co-Efficient of 0th Polynomial 4 Enter Size of 2 Polynomial 5 Enter x^0 Co-Efficient of 1th Polynomial 1 Enter x^1 Co-Efficient of 1th Polynomial 2 Enter x^2 Co-Efficient of 1th Polynomial 3 Enter x^3 Co-Efficient of 1th Polynomial 4 Enter x^4 Co-Efficient of 1th Polynomial 5 Enter Size of 3 Polynomial 2 Enter x^0 Co-Efficient of 2th Polynomial 1 Enter x^1 Co-Efficient of 2th Polynomial 2 Enter Size of 4 Polynomial 7 Enter x^0 Co-Efficient of 3th Polynomial 1 Enter x^1 Co-Efficient of 3th Polynomial 2 Enter x^2 Co-Efficient of 3th Polynomial 3 Enter x^3 Co-Efficient of 3th Polynomial 4 Enter x^4 Co-Efficient of 3th Polynomial 5 Enter x^5 Co-Efficient of 3th Polynomial 6 Enter x^6 Co-Efficient of 3th Polynomial 7 7 x^6 + 6 x^5 + 10 x^4 + 8 x^3 + 10 x^2 + 9 x^1 + 5 x^0
Explanation:
//Coming Soon..