This blog is under construction

Monday 8 July 2013

C program to calculate Grades

Write a C program to calculate Grades.


  #include <stdio.h>
  int main() {
        int marks[5], average, total = 0, grade, i;

        /* input marks from the user */
        printf("Enter your five subject marks:\n");
        for (i = 0; i < 5; i++) {
                printf("Enter Mark for Subject %d: ", i + 1);
                scanf("%d", &marks[i]);
        }

        /* find the total marks */
        for (i = 0; i < 5; i++) {
                total = total + marks[i];
        }

        /* calculate the average */
        average = total / 5;

        /* find the grade */
        if (average > 95) {
                grade = 'S';
        } else if (average > 90) {
                grade = 'A';
        } else if (average > 80) {
                grade = 'B';
        } else if (average > 70) {
                grade = 'C';
        } else {
                grade = 'D';
        }

        /* print the outputs */
        printf("Total Marks: %d\n", total);
        printf("Average    : %d\n", average);
        printf("Grade      : %c\n", grade);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your five subject marks:
  Enter Mark for Subject 1: 100
  Enter Mark for Subject 2: 80
  Enter Mark for Subject 3: 90
  Enter Mark for Subject 4: 75
  Enter Mark for Subject 5: 99

  Total Marks: 444
  Average    : 88
  Grade       : B





See Also:

1 comment:

  1. Nice blog.Thanks for sharing.Have a look on custom software development company,if you want any software solutions.we bring to you the BEST solutions at nominal rates.

    ReplyDelete