Question: C Programming Array Problem Step 1 In a single program: Create an array of longs (make a constant for the size and set it to
C Programming Array Problem
Step 1
In a single program:
- Create an array of longs (make a constant for the size and set it to 4 or 5 for testing).
- Initialize all the array elements to zero.
- Populate the array with numbers you read from the user. Use a FOR loop.
- Print all the numbers in the array.
- Calculate the array total and print.
- Calculate the array average and print.
- Find the maximum array value and print.
- Add all the numbers at every even location (starting at 0) and print the total.
- Add all the even numbers in the array and print the total.
Step 2
- Dont start on this until you have Step 1 completely finished.
- Convert items 2-9 in step 1 to subroutines and/or functions. You can remove the code from step 1 in main after you convert to functions/subroutines. Don't forget your procedure comment blocks.
- Call each of the above functions from your main subroutine and display the results. For example:
For example:
// Constants
const long lngARRAY_SIZE = 5;
// Prototype
void InitializeArray( long alngValues[ ] );
void PopulateArray( long alngValues[ ] );
...
void main( )
{
long lngTotal = 0;
// 1 Create Array
long alngValues[ 5 ]; // Can't use constant in declaration
// 2 Initialize Array
InitializeArray( alngValues );
// 3 Populate Array
PopulateArray( alngValues );
...
// 5 Calculate Array Total
lngTotal = CalculateArrayTotal( alngValues );
printf( "#5 Array Total = %ld ", lngTotal );
}
void InitializeArray( long alngValues[ ] )
{
...
}

Step 1 In a single program: 1. Create an array of longs (make a constant for the size and set it to 4 or 5 for testing). 2. Initialize all the array elements to zero. 3. Populate the array with numbers you read from the user. Use a FOR loop. 4. Print all the numbers in the array. 5. Calculate the array total and print. 6. Calculate the array average and print. 7. Find the maximum array value and print. 8. Add all the numbers at every even location (starting at 0) and print the total. 9. Add all the even numbers in the array and print the total. Step 2 Don't start on this until you have Step 1 completely finished. Convert items 2-9 in step 1 to subroutines and/or functions. You can remove the code from step 1 in main after you convert to functions/subroutines. Don't forget your procedure comment blocks. Call each of the above functions from your main subroutine and display the results. For example: For example: // Constants const long IngARRAY_SIZE = 5; // Prototype void InitializeArray( long alngValues[]); void PopulateArray( long alngValues[]); void main() { long IngTotal = 0; // 1 - Create Array long alngValues[5]; 11 2 - Initialize Array InitializeArray( alngValues ); // Can't use constant in declaration 1/3 - Populate Array PopulateArray( alngValues ); 115 - Calculate Array Total IngTotal = CalculateArray Total alngValues ); printf("#5 - Array Total = %ld ", IngTotal); } void InitializeArray( long alngValues[]) { }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
