C Program to Calculate the Sum of Alternating Series 1-2+3-4...+98-99
The program calculates the sum of the alternating series 1-2+3-4+...+98-99.
'i' is used as the loop counter, running from 1 to 99 (excluding 100).
'sn' stores the sum of the series, initialized to 0.
'sign' alternates the signs of terms, starting at 1.
Inside the loop, 'sn' is updated by adding the product of 'sign' and 'i'. Then, 'sign' is negated.
After the loop, the final value of 'sn' is printed using printf.
The output of the program is -50.
原文地址: https://www.cveoy.top/t/topic/mY9O 著作权归作者所有。请勿转载和采集!