Question: hi everyone. i generated this array program in C ; however, i need to rearrange the main before the prototype functions please help. here are
hi everyone. i generated this array program in C; however, i need to rearrange the main before the prototype functions please help. here are my instructions and code:
Instructions:
Write a small program that:
1-fills an array of doubles with user input,
2-prints the doubles on the screen in a column,
3-adds up all the doubles in the array
4-prints the sum onto the screen.
- You must use at least 3 functions 1- Declare an array of doubles of size 12. 2- Prompt the user for how many doubles they want to enter <= 12. 3- Use a loop to read the doubles into the array from the keyboard. 4- Use a loop to print the array onto the screen in a column. 5- Use a loop to add up all the items in the array and store the sum 6- print the sum onto the screen
#define _CRT_SECURE_NO_WARNINGS 1 #include
double calculateSum(double doubleArray[], int n) { int i; double sum = 0; // Use a loop to add up all the items in the array and store the sum for (i = 0; i
// Use a loop to print the array onto the screen in a column. void displayArray(double doubleArray[], int n) { int i; printf(" Double Array: "); // Use a loop to print the array onto the screen in a column. for (i = 0; i
int checkSize(int n) { if (n >= 1 && n <= 12) return 1; else return 0; }
int main() { // Declare an array of doubles of size 12. double doubleArray[12];
// Prompt the user for how many doubles they want to enter <= 12. int n, i;
while (1) { printf("How many doubles you want to enter.(less than equal to 12): "); scanf("%d", &n);
if (checkSize(n) == 1) break; else printf("Invalid Input "); }
// Use a loop to read the doubles into the array from the keyboard. printf("Enter the doubles "); for (i = 0; i
displayArray(doubleArray, n);
double sum = calculateSum(doubleArray, n);
printf(" Array sum:%lf ", sum);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
