C Program for Alternating Series Calculation A C program is created to print a series of numbers alternating between addition and subtraction, specifically 1 - 2 + 3 - 4 up to a given number n. The program initializes variables for the loop and sum calculation, reading the value of n from user input. A while loop iterates through each integer up to n; if an integer is even, it prints with a minus sign and subtracts from the sum; if odd, it prints with a plus sign and adds to the sum.
Execution Results of Series Sum When running this program with different inputs like n = 10 or n = 5, it successfully outputs both the series generated by these rules as well as their respective sums (-5 for ten terms and +3 for five terms). Each iteration updates values accordingly: printing current integers in sequence while adjusting cumulative totals based on whether they are added or subtracted according to their parity (odd/even). This demonstrates how structured programming can effectively manage arithmetic sequences using loops.