Question

Write an algorithm and a program in ‘C’ language for addition of two Polynomials

13 Sep 2024
Answer :
Word Count : 1165

### 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 : size2;
    
    // Initialize the sum array
    for (int i = 0; i < maxSize; i++) {
        sumPoly[i] = 0; // Initialize with zero
    }
    
    // Add the polynomials
    for (int i = 0; i < size1; i++) {
        sumPoly[i] += poly1[i]; // Add coefficients of first polynomial
    }
    
    for (int i = 0; i < size2; i++) {
        sumPoly[i] += poly2[i]; // Add coefficients of second polynomial
    }
}

// Function to print the polynomial
void printPolynomial(int *poly,

________ ________ ________ ________ _____ _____ __________ ___.
____ _________ ____ __________ _____ ____ ________ _________ ______ _________ _______ ____.
__________ __________ ________ ____ ______ ___ ________.
____ _________ ______ ___ ___ ________ _____ __________ _______ ___.
______ _________ ___ ____ _______ ________ _____ ___ _______ __________.
_____ ________ _______ ________ _______ ____ ___ ________ ______ _______.
_________ ______ ______ ____ ___ ___ _____ __________ ____ __________ __________ _________.
______ __________ ___ _______ __________ ____ ____ _________ _________ ______.
_______ ____ ____ _____ _______ ___ _____ ___ ______ ________ _______ _______.
_____ __________ _________ ___ ____ _______ _________ ________.
__________ ___ ________ _______ ________ __________ ________ _________ _____ _____ _________.
________ ____ _________ ____ __________ __________ ________ _____.
__________ ___ ______ ______ _________ _____ __________ _________ ____.
_______ ___ _____ ______ _________ ______ _____ ____ ________.
______ ______ _______ ___ ______ ________.
________ _________ ________ ____ ______ ____ _____ _________ _________ ______ _________.
_________ ___ ___ ______ ________ ________.
_____ ________ __________ _______ ___.
___ __________ _________ _____ ____.
__________ ______ ____ ________ ________ _____ _____ ______ _________ ________ ______ ________.
________ _____ _____ ________ ______ __________ ___.
____ ___ _________ _______ ________ _______ ________.
___ _______ ______ _____ _______ ___ ____.
__________ _______ _______ ___ __________ ____ ____ _________.
_____ ______ _________ __________ ________ ___ ____ __________ __________ _____ ____.
_________ _____ __________ ______ ____ ________ ______ _______.
__________ __________ __________ _________ _______ ______ _____ ______ _____ __________.
__________ ____ __________ ____ ________ _____ __________ __________ ___ ________ ___.
___ __________ _______ ______ ____ ____ ___ _________ _______ __________ _______.
________ __________ _______ ________ _______ ___ _____ _____.
_____ _________ ___ ____ ____ _______ __________.
_____ __________ __________ _________ _________ __________ ____ __________.
_________ _______ ________ _______ ____ __________ _________ ___.
______ ___ __________ ___ ___ ______ _____.
_______ __________ __________ __________ ____ ___.
____ ___ _______ ____ ____ ____ ______ __________ ____ ___ ______ __________.
___ ___ _____ ________ ____ ____ _______ __________ _______ ___ __________ ______.
_______ _____ ____ ______ ____ __________ ____.
________ ________ __________ _____ ______ ________ ________ _______ ___.
________ _________ ________ ____ _____ _________ ______.
______ ___ ____ ________ __________ __________.
______ _______ _______ _____ __________ ___ ________ ________ ____ _____.
_____ ________ ____ ___ _____ _________ ___ ________ __________ ______ ______.
___ _______ ________ ___ ___ ________ __________ ___.
__________ ___ ___ ______ ____ _____.
________ _________ ___ ____ ________ ________ _______ _________ _________.
________ __________ __________ ____ __________ ______ _______ ________.
______ ____ _____ __________ ____ _______ ___ _______ _____ ___ ______ ________.
_______ ______ ________ _________ ________ ______ _____.
______ _________ ___ _______ ______ _______ _______ ______ _____ ______ _______ _________.
_________ _______ _________ ____ _______.
______ _____ _____ _______ _____ _________ _____.
_______ ______ __________ ________ _______ _____ _________ ________ _________ _________.
________ ___ ____ ___ _______ __________ ________ __________.
____ _________ ____ ______ _____ __________ ____ ____ ________.
________ __________ ________ ____ ___ __________ _______ _________ ___.
________ ___ _____ ___ ________ _________ _____ _____ _______ ________.
__________ __________ ____ ________ ____ _________ _____ ______.
_______ ________ _____ _________ __________ ________ _________ __________ __________ _______ _________ _________.
____ ________ ___ _____ ______ ________ ________ ___.
____ ___ ___ ______ ________.
_________ _________ _______ _______ ____ ________.
_________ ________ _______ ____ ____ ________ _____ ___ _______ __________ ________ _______.
_______ ________ ___ _________ __________ _________.
____ __________ _______ ______ ______ _______ ________ _________ _________.
__________ ____ ________ ____ ________ ______ _________ ____ ____ ________.
_______ ___ _______ _________ ________ _____ ____ ______ ________.
____ _______ ____ _______ ________ ________ ____ _____ ___ _____ ________.
_____ _______ _________ ________ __________.
__________ _________ _____ _________ _______ _________ __________ ________ ______ _____.
______ ____ __________ _________ ______ __________ _________ ________ ______ _____ __________.
____ _________ _____ ______ __________ _________ ________ _____ ________ ________ ___.
__________ ______ ___ _____ ____.
_________ ___ _______ _____ ______ _______ _________.
_____ ____ ______ _________ __________ ___ _____ _______ ___.
_____ _________ _________ __________ _________ ____ _________.
_____ ______ __________ ___ _________ __________ _________ ______ __________ _______ ___.
__________ ________ ____ __________ ______.
_________ ___ ____ __________ __________ _______.
____ _________ ____ _______ _______.
________ ________ ____ _______ ____.
______ _______ ____ _____ _________ ______ ________ _____ _________ ______ ________.
_________ _______ ___ __________ ___ _________ ___ ____ _________ _______.
________ ________ ___ _________ __________.
_________ ____ ______ ________ ______.
_____ _____ __________ _________ _______ _____ ____ ________ __________.
_________ __________ ______ _______ _____ __________ ___ ______ ___ ___ _____.
_______ ___ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCSL 209 2024 2025 - Write an algorithm and a program in ‘C’ language for addit | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→