Sunday, February 13, 2022

Computation of Grades in C

 A simple program to solve the grades of the students using a  C programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

Thank you very much for your support.





Program Listing

#include <stdio.h>
#include <stdlib.h>

int sum_of_array(int array[], int size)
{
int sum = 0;

for (int i = 0; i < size; ++i)
sum += array[i];

return sum;
}

char getGrade(int grade)
{
if (grade >= 91 && grade <= 100)
return 'A';
else if (grade >= 81 && grade <= 90)
return 'B';
else if (grade >= 71 && grade <= 80)
return 'C';
else if (grade >= 61 && grade <= 70)
return 'D';
else if (grade <= 60)
return 'E';

return 0;
}

int main()
{
printf("\n");
printf("\tComputation of Grades in C");
printf("\n\n");
printf("How many grades: ");
int num_grades;
scanf("%d", &num_grades);
int *grades = malloc(num_grades * sizeof(int));
for (int i = 0; i < num_grades; ++i)
{
printf("Enter grade %d: ", i + 1);
scanf("%d", &grades[i]);
}
int total_sum = sum_of_array(grades, num_grades);
  int avg = (total_sum / num_grades) * 10;
  printf("\n");
  printf("Your Grade is %d: \tDescriptive Rating: %c", avg, getGrade(avg));
  printf("\n");
  free(grades);

return 0;
}

No comments:

Post a Comment