Write an algorithm and a program in ‘C’ language for addition of two Polynomials
### Algorithm for Addition of Two Polynomials
1. Input Representation:
- Represent polynomials as arrays of coefficients. For a polynomial \( P(x) = a_nx^n + a_{n-1}x^{n-1} + \dots + a_1x + a_0 \), use an array `P[]` where `P[i]` stores the coefficient of \( x^i \).
2. Input the Polynomials:
- Take two polynomials of the form:
- Polynomial 1: \( P1(x) = a_nx^n + a_{n-1}x^{n-1} + \dots + a_1x + a_0 \)
- Polynomial 2: \( P2(x) = b_nx^n + b_{n-1}x^{n-1} + \dots + b_1x + b_0 \)
- Each polynomial is stored in an array, with indices corresponding to the powers of \( x \).
3. Adjust for Different Polynomial Sizes:
- Determine the degree of both polynomials (highest power of \( x \)) and make both arrays of equal length by padding the shorter array with zeros.
4. Add the Polynomials:
- Initialize a new array `sum[]` of the same size as the largest polynomial.
- For each corresponding index in the polynomials, add the coefficients of the same power of \( x \) and store the result in the `sum[]` array.
5. Output the Result:
- Traverse the `sum[]` array and print the result in polynomial form, skipping any terms where the coefficient is zero.
### C Program for Addition of Two Polynomials
```c
#include <stdio.h>
#include <stdlib.h>
// Function to add two polynomials
void addPolynomials(int *poly1, int *poly2, int *sumPoly, int size1, int size2) {
// Find the maximum degree of the two polynomials
int maxSize = (size1 > size2) ? size1 : _______ _________ _____ ________ _________ ___ ____ ____ __________.
_______ __________ _________ _______ _____ ____ ________.
_________ ____ ________ _____ _________ __________.
______ ___ _____ _________ _____ _____ _______ ______ _____ ______ _______.
________ ___ _________ __________ _______ ___ _______ _____ ____.
______ ________ ______ ____ _________.
__________ ____ ____ ___ _________.
_________ _______ __________ ___ _________ ________.
_________ __________ ________ ____ _____ _______ __________ ______ ___ _________ ____.
_______ __________ _______ ____ _____ ______ _________ ________ _______ _________.
___ ______ ___ _________ _________ _____ _____.
______ ______ ___ ______ ________ _________ ______ ___ __________ ___ ________.
__________ _________ _________ __________ _______ ____ _____ ______ ________ _________ ______ ___.
________ ______ ___ ______ ________ ____ _________.
________ _________ _______ _________ _______ ______.
_______ _________ _____ ___ ______ ___.
____ _______ __________ _________ _____ ____.
_____ ___ ___ ____ ___ _____ ________ ______ __________.
________ _______ _____ _________ ___ ___ ______.
_______ ____ _________ ________ _____ _______ _____ _________ _________ _____ __________.
________ __________ ________ _______ ________ ______ ___ ____ _______.
________ __________ ________ _________ ___ __________ _________ _______.
_________ _______ ______ __________ ____ ______ ____ _____.
______ ______ ____ __________ __________ _________ __________.
____ _____ ________ _____ __________ _____ _______.
___ ___ _______ _____ ______ ______.
____ __________ __________ ________ ___ _____ __________ __________.
__________ _________ ____ ______ _________ ______ _____ _________ _________.
__________ ___ _______ _____ ___ ______ __________ _______ ____ __________ ____.
________ ______ ________ ________ ________ _____ _______ _______ ________ __________.
___ ______ ______ ________ _____ ___ ____ _________ _______ ___.
___ _____ ______ _________ ______ ____ ___ ___ ______ ____.
_________ ________ __________ ___ ____.
__________ ________ ______ ______ _______ ________.
_____ __________ _________ ________ _______ ______ ____ ___ ______.
__________ ____ _______ __________ _______ ________ ___ ________ ________ ____.
____ _________ _______ __________ _____ _________ ________ __________ _____ _____ _____.
_____ _____ __________ ___ _________.
______ ____ ______ ___ _____ ___ ____ _______.
_____ _________ ______ _______ __________ ____ ___ _________ ____.
_______ _________ ___ __________ ____ ________ ______ ____ _____ _____ _____ _________.
_______ _________ __________ ____ _________ _______ ______ ______ ____.
__________ ______ _______ ____ _________ ______ _____ ____ __________.
______ __________ ___ _________ _____ __________ ____ ___ ____.
______ __________ ________ _________ _________ ____ ________ __________.
___ ___ __________ ____ ___ __________ ________.
_____ _________ _______ _________ __________ _______.
_________ __________ ______ _________ __________ ____ ____ _________.
___ ______ __________ _____ _______ __________ _________ ____ _______ ____ _____ _____.
_______ ____ _____ _____ ______ ______.
_______ ____ ________ __________ _______ ________ ______ __________ __________.
__________ ___ ______ __________ ____.
____ _______ _____ ____ ____ ______.
______ _______ _______ _____ __________ ______ _____ _________ ____ _______ ___.
_______ ______ _________ ______ ____ ___ _____ ________ ______ ____ ________ _____.
___ _______ _____ ________ _____ _____.
_______ _______ ________ _________ _____ ____ _________ ______.
_________ _________ _________ __________ _________ ________ ____ _________.
__________ ________ _____ _______ _________ ____.
______ ____ __________ ___ _______ _______ ___ _______ ____.
_______ ___ ________ _______ __________ _______ _____ __________.
_______ ____ _____ ______ ______ _________ ___ __________ ____ ________ ______.
___ ____ __________ _______ _______ _____ ___ _________ _______ __________.
_______ _____ ___ ____ _______ __________ ___ ________ _________.
______ _______ __________ ________ _____ ____.
________ ___ _____ __________ __________ ___ ___ _____ __________ ___.
__________ ______ ________ _________ _________.
________ ________ _________ ________ __________ __________ ______.
____ __________ ______ ____ ________ ____ _____ ____ _________ ___ _______ ____.
_______ ___ _________ ________ _________.
__________ ____ __________ ___ _______ _________.
____ _________ __________ _________ ____ __________ _________ __________ _______ ________.
___ ________ __________ _____ ________ ____ __________.
______ _____ _______ _________ _______ ____ _____ __________ ___ _______ ______ _____.
__________ _____ ________ _________ __________ _________ ______ _________ __________.
_____ ______ _________ ____ _________ ___ ____ ____ _______ __________ _________ __________.
_____ ______ __________ _________ ________ ___ _____ _________ _____.
___ ______ _______ __________ __________.
__________ _________ ____ _________ __________.
____ _______ _______ __________ _______ ______.
________ ________ _____ __________ ___ ______.
__________ ______ _____ ______ _____ ___ ________.
_____ ______ ________ __________ _______.
________ _____ ______ ________ _________ ____.
_______ _______ _______ ______ __________ ____ _________ ________ ________ _________ _____ __________.
_______ ____ __________ ________ __________ _________ _________ ________ ____.
__________ _________ _______ ________ __________ ______ ___.
_______ __________ _______ ___ ______ ________.
_________ ___ _______ __________ _____ ____ _________.
_______ _____ ____ _____ ____ _____ ______ _________.
____ ____ ____ ______ ______ ____ ______ ________ ____ ________ ____ _____.
_________ _____ ___ _________ ____.
_____ _________ ______ ________ ______ __________ ________ ____.
_______ ___ ___ ___ _______ _____ ________ ______.
__________ ________ ________ ________ _______ _______ _______ ________ ______ ___.
___ __________ ________ ________ ____ ____ ________ _______ _______.
____ ___ __________ _______ ________ _______ _________ _____ ______ _______.
________ _____ _______ ___ ______ _________ ______.
_____ ________ _____ ________ _____ __________ ___ _______ ____ __________.
___ _____ ___ _______ _________ ______ ___ _______ __________ _______ ______.
________ ________ _________ _______ ______ __________.
______ ____ ______ ___ _____ _____ ___ ___.
_________ _____ _______ ______ ____ _____ ___ ________ __________.
_____ ____ _____ ____ ____ ________ _____ __________ ________.
_________ __________ ____ __________ _____ __________ ______.
__________ __________ ________ ____ _______ ____.
________ _______ __________ ____ _______ _____ ___ ________ _________.
Get Full Answer on WhatsApp