Write a complete C program that accepts 15 float grades into an array ana prints
ID: 675332 • Letter: W
Question
Write a complete C program that accepts 15 float grades into an array ana prints out the array along with the letter grade of each number. At the end print out the highest grade, the lowest grade and the average grade of the class. Use a for loop in main to load the array. Write two functions: displayGrade, which will print out the number and the letter grade; and calcGrade, which will determine the highest grade and the lowest grade and the average grade of the class and pass these three variables back to main to be printed. You may not use global variables.Explanation / Answer
#include <stdio.h>
int main() //Program Start
{
float numbers[10],result; //definition of float variables and numbers[10] is a array
int i,p,k; //definition of integer variables
printf("The program take 15 float numbers and organize in decreasing order. ");
//print message to enter 15 numbers
printf("enter 15 numbers:(Note:enter one number and press enter) ");
for(i=0;i<15;i++) //loop for input
scanf("%f",&numbers[i]); //the input numbers are save in numbers[i]
//print message of the numbers the user enter
printf("Numbers that you enter are: %f %f %f %f %f %f %f %f %f %f ",numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6],numbers[7],numbers[8],numbers[9]);
//print a message of the numbers in decreasing order
printf("decreasing order: ");
for(i=10;i>=0;i--) //loop for compare the numbers enter
{ for(k=10;k>=0;k--) //loop for compare the numbers with the array numbers[k]
{ if(numbers[i]<numbers[k]) //compare
{
result=numbers[i]; //save number
numbers[i]=numbers[k]; //save the greater number one after another
numbers[k]=result; } } }
//print the numbers in decreasing number
printf(" %f %f %f %f %f %f %f %f %f %f ",numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6],numbers[7],numbers[8],numbers[9]);
// Message to exit the program
printf ("Press any botton and enter ");
scanf ("%x",&p);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.