# Answered! Write the code needed so pi, is used throughout a C source file to represent the math constant 3.14 without declaring…

Write the code needed so pi, is used throughout a C source file to represent the math constant 3.14 without declaring a variable or using #define.

(C PROGRAM)

Don't use plagiarized sources. Get Your Custom Essay on
Answered! Write the code needed so pi, is used throughout a C source file to represent the math constant 3.14 without declaring…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

```#include <stdio.h>   // Needed to use IO functions

int main() {
int sumOdd  = 0; // For accumulating odd numbers, init to 0
int sumEven = 0; // For accumulating even numbers, init to 0
int upperbound;  // Sum from 1 to this upperbound
int absDiff;     // The absolute difference between the two sums

// Prompt user for an upperbound
printf("Enter the upperbound: ");
scanf("%d", &upperbound);   // Use %d to read an int

// Use a while-loop to repeatedly add 1, 2, 3,..., to the upperbound
int number = 1;
while (number <= upperbound) {
if (number % 2 == 0) {  // Even number
sumEven += number;   // Add number into sumEven
} else {                // Odd number
sumOdd += number;    // Add number into sumOdd
}
++number; // increment number by 1
}

// Compute the absolute difference between the two sums
if (sumOdd > sumEven) {
absDiff = sumOdd - sumEven;
} else {
absDiff = sumEven - sumOdd;
}

// Print the results
printf("The sum of odd numbers is %d.n", sumOdd);
printf("The sum of even numbers is %d.n", sumEven);
printf("The absolute difference is %d.n", absDiff);

return 0;
}```