In: Computer Science
My Assumption here is
A -> 4
B -> 3
C -> 2
D -> 1
E -> 0
Here is the code
=============================================================
#include <stdio.h>
#include <stdlib.h>
int main(){
char grades[5];
int nums[5];
char temp; // To clear the buffer
printf("\nEnter grades of 5 subjects:\n\n");
for(int i = 0;i < 5; i++)
{
printf("Enter Grade of subject %d:", (i+1));
scanf("%c%c", &grades[i], &temp);
if(grades[i] == 'A'){
nums[i] = 4;
}
else if(grades[i] == 'B'){
nums[i] = 3;
}
else if(grades[i] == 'C'){
nums[i] = 2;
}
else if(grades[i] == 'D'){
nums[i] = 1;
}
else if(grades[i] == 'E'){
nums[i] = 0;
}
else{
printf("\nInvalid Marks\n Please try again");
i--; // So as to ask input for the same number again
}
}
for(int i = 0; i < 5; i++){
printf("\nNumber for subject %d is %d", (i+1), nums[i]);
}
return 0;
}
=============================================================