Finish the function compute_GPA below. The function should return the average of the grades (assume that A=4,B=3,C=2,D=1, and F=0). The grades array will contain letter grades (A,B,C,D, or F, either upper-case or lower-case 大寫小寫), n is the length of the array
寫compute_GPA函數。函數會return成績平均(A = 4, B = 3, C = 2, D = 1, F = 0)
#include <stdio.h>
float compute_GPA(char grades[],int n)
{
/*INSERT YOUR CODE HERE*/
/*END OF YOUR CODE*/
//The function should return the average of the grades(assume that A=4,B=3,C=2,D=1, and F=0).
}
int main(void)
{
char G[100];
int n;
/*INSERT YOUR CODE HERE*/
/*END OF YOUR CODE*/
printf("%g",compute_GPA(G,n));
return 0;
}
Example input:
The first input is the number of elements need to compute GPA (4); The array values follow;
第一行是成績數目,第二行是成績(A/B/C/D/F)
4
A B C D
Example output
2.5
Remember: You may correct the cases, but your code always be revised!