Tuesday, 9 September 2025

Print addition symbol in polynomials


#include <stdio.h>

int main() {

    int n; // Degree of the polynomial + 1

    printf("Enter the number of terms in the polynomial: ");

    scanf("%d", &n);


    int poly1[100]; // Array for polynomial coefficients


    // Input for the polynomial

    printf("Enter the coefficients of the polynomial:\n");

    for (int i = 0; i < n; i++) {

        printf("Coefficient of x^%d: ", i);

        scanf("%d", &poly1[i]);

    }


    // Print polynomial

    printf("\nPolynomial is: ");

      for (int i = 0; i < n; i++) {

        printf("%d", poly1[i]);

        if (i != 0) {

            printf("x^%d", i); // Display power of x

        }

        if (i != n - 1) {

            printf(" + "); // Display '+' between terms in result

        }

    }   

    return 0;

}