Make a program storing 5 student grades with each student to take 3 courses. the input is from 0-100 score into 0-4 (GPA) in the array form. use c language
Score 1 | Score 2 | score 3 | GPA | |
Std 1 | ||||
std 2 | ||||
std 3 | ||||
std 4 | ||||
std 5 |
GPA calculation:
Code Explanation:
Code:
#include <stdio.h>
float gpa(float array[]);
int print_table(float ar1[],float GPA,int n);
int main()
{
float std1_scores[3] = {90.0,65.0,98.0};
float std2_scores[3] = {78,90.7,67.5};
float std3_scores[3] = {92.5,93.3,97.8};
float std4_scores[3] = {80.0,90.0,70.0};
float std5_scores[3] = {56.1,65.4,45.2};
float GPA1 = gpa(std1_scores);
float GPA2 = gpa(std2_scores);
float GPA3 = gpa(std3_scores);
float GPA4 = gpa(std4_scores);
float GPA5 = gpa(std5_scores);
printf("\t\tScore1\t\tScore2\t\tScore3\t\tGPA\n");
print_table(std1_scores,GPA1,1);
print_table(std2_scores,GPA2,2);
print_table(std3_scores,GPA3,3);
print_table(std4_scores,GPA4,4);
print_table(std5_scores,GPA5,5);
return 0;
}
float gpa(float std_scores[]){
float avg;
float sum = 0;
for(int i=0;i<3;i++){
sum = sum + std_scores[i];
}
avg = sum/3;
return(avg/10);
}
int print_table(float x[], float GPA, int n){
printf("std %d",n);
printf("\t\t%f\t%f\t%f\t%.1f\n",x[0],x[1],x[2],GPA);
return 0;
}
O/P:
Score1 Score2 Score3 GPA
std 1 90.000000 65.000000 98.000000 8.4
std 2 78.000000 90.699997 67.500000 7.9
std 3 92.500000 93.300003 97.800003 9.5
std 4 80.000000 90.000000 70.000000 8.0
std 5 56.099998 65.400002 45.200001 5.6
Code Screenshot:
O/P Screenshot:
Get Answers For Free
Most questions answered within 1 hours.