Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS101 / KCS201 Programming for Problem Solving - Using C Language


Lab Exercises


10. Write a program that accepts marks of five subjects and finds percentage and prints grades according to the following criteria:
Between
90-100% ----------------------------- Print 'A'
80-90% ------------------------------ Print 'B'
60-80% ------------------------------ Print 'C'
Below 60% ------------------------- Print 'D'.


/*
 File: Prgrm10.c
 Author: Aditya Saini
 Date: Sept 24, 2019
 Description: Program to find and print percentage of five subject marks and grades.
*/

#include <stdio.h>

int main (void)
{
               int subject_1, subject_2, subject_3, subject_4, subject_5;
               int sum;
               float percentage;
               char grade;

               //Input 5 subjects marks.
               printf ("Input first subject marks: ");
               scanf ("%d", &subject_1);
               printf ("Input second subject marks: ");
               scanf ("%d", &subject_2);
               printf ("Input third subject marks: ");
               scanf ("%d", &subject_3);
               printf ("Input forth subject marks: ");
               scanf ("%d", &subject_4);
               printf ("Input fifth subject marks: ");
               scanf ("%d", &subject_5);

               //Calculate the sum and percentage.
               sum = subject_1 + subject_2 + subject_3 + subject_4 + subject_5;
               percentage = sum / 5.0;

               //Calculate the grade.
               if (percentage >= 90)
                              grade = 'A';
               else if (percentage >= 80)
                              grade = 'B';
               else if (percentage >= 60)
                              grade = 'C';
               else
                              grade = 'D';

               //Output the result.
               printf ("Total marks: %d\n", sum);
               printf ("Percentage: %.2f %\n", percentage);
               printf ("Grade: %c", grade);

               return 0;
};

Output

Input first subject marks: 84
Input second subject marks: 95
Input third subject marks: 79
Input forth subject marks: 83
Input fifth subject marks: 89
Total marks: 430
Percentage: 86.00 %
Grade: B



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib