Question

In: Computer Science

MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...

MUST BE DONE IN C (NOT C++)

In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines:

- Your program should ask the user for the number of students that are in the class. This number should help you declare your array.

- Use the function seen in class to scan the grades of the array. In other words, we will populate the array with a function.

- When done, use the printing function seen in class to make sure all grades were scanned correctly.

- Then, call the “average” function. This function will receive two parameters, the array’s length and the array. Inside the function, you will calculate the average (using a loop) and you will return the average.

- In main, you will received this returned value and print it.

Solutions

Expert Solution

C CODE :

#include <stdio.h>
float average(int a[], int x)
{
int sum = 0;
float avg = 0;
for(int i = 0; i < x; i++)
{
sum += a[i]; // do sum of the grades
}
avg = (float) sum / x; // then divide it by size to calculate average
return avg; // return average
}

int main()
{
int x;
printf("Enter the number of students in the class : ");
scanf("%d", &x); // read the number of students
  
int a[x];
printf("Enter the grades of each person in the class : ");
for(int i = 0; i < x; i++)
{
scanf("%d", &a[i]); // read the grades of the students
}
  
printf("The enteres grades are : ");
for(int i = 0; i < x; i++)
{
printf("%d ", a[i]); // print the grades to confirm
}
  
float avg = average(a, x);
printf("\nAverage of the grades are : %f", avg); // print the average of the grades
return 0;
}

SCREENSHOT OF THE C CODE :


Related Solutions

(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First,...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First, declare and initialize a string. You can name the variable whichever way you want and you can initialize it to whichever value you want. Then, use a for loop to print its characters; one at a time, until you reach the null character. After this, go ahead and declare a second string (since you are not initializing it right away, you will have to...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
Must be done in C Write a C program found out the maximum value between the...
Must be done in C Write a C program found out the maximum value between the three numbers? Show steps with comments or else it will be flagged.
This program must be done in JAVA. Write a program to monitor the flow of an...
This program must be done in JAVA. Write a program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first...
OBJECTIVE-C For this program a teacher needs to be able to calculate an average of test...
OBJECTIVE-C For this program a teacher needs to be able to calculate an average of test scores for students in their course. Your program must ask the Professor ho many students and how many tests will be averaged per student. Your program should then allow the Professor to enter scores for each student one at a time and then average those scores together. For example, if a student has 5 scores to be entered and the scores are 80, 60,...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
Must be done with the Program Raptor Program #2 - Area of Shapes Design a superclass...
Must be done with the Program Raptor Program #2 - Area of Shapes Design a superclass called Shape that contains two functions—getVolume() and getInput(). The getVolume and getInput functions in the Shape class will simply return 0, you will derive from them in your subclasses mentioned below. Define 3 subclasses of the Shape class—Sphere, Cube, and Cone. The sphere class will need a radius field, the cube class will need a length field, and the cone class will need radius...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT