/* This is the ninth lab of Lab EE107
The purpose of this lab understand how a program that calculates the average of the elements inside
an array of 10 floating point values and uses two ways of initializing the array.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: March 25th, 2024.
*/
#include <stdio.h>
int main() {
float numbers_EU[10]; // Array to store floating-point values
float sum_EU = 0.0; // Variable to store the sum of elements
// Method 1: Initializing array using scanf
printf("Enter 10 floating-point numbers:\n");
for (int i_EU = 0; i_EU < 10; i_EU++) {
scanf("%f", &numbers_EU[i_EU]); // Read input from user
sum_EU += numbers_EU[i_EU]; // Add the value to sum
}
// Calculate average
float average_EU = sum_EU / 10.0;
printf("Method 1:\n");
printf("Average of the numbers: %.2f\n", average_EU);
// Method 2: Directly initializing values in the code
float numbers2_EU[10] = {1.5, 2.3, 3.7, 4.2, 5.1, 6.8, 7.4, 8.9, 9.6, 10.0};
sum_EU = 0.0; // Reset sum for the second method
// Calculate sum
for (int i_EU = 0; i_EU < 10; i_EU++) {
sum_EU += numbers2_EU[i_EU];
}
// Calculate average
average_EU = sum_EU / 10.0;
printf("\nMethod 2:\n");
printf("Average of the numbers: %.2f\n", average_EU);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: