Tech Unleashed

Wohoo!! We're on YouTube

Saturday, 15 January 2022

C program for " if the marks obtained by a student in five different subject are input through the keyboard, find out the aggregate marks and percentage obtained by the student. Assume that the maximum that can be obtained by a student in each subject is 100. Also determine the grade he got."

Problem: C program for " if the marks obtained by a student in five different subject are input through the keyboard, find out the aggregate marks and percentage obtained by the student. Assume that the maximum that can be obtained by a student in each subject is 100. Also determine the grade he got."
Grade system: 
A : if the percentage scored is more than 90.
B : if the percentage scored is in between 81 to 90.
C : if the percentage scored is in between 71 to 80.
D : if the percentage scored is in between 61 to 70.
E : if the percentage scored is in between 51 to 60.
F : if the percentage scored is in between 41 to 50.
fail : if the percentage scored is less than 40.

Formulae used:
Aggregate marks = sub1 + sub2 + sub3 + sub4 + sub5
Average marks = aggregate marks / 5
Percentage = ( aggregate marks x 100 ) / 500

C program:

// Program by shyam kanth

#include<stdio.h>

int main(){
    int sub1, sub2, sub3, sub4, sub5, sum;
    float per;
    printf("Enter the marks of five subjects : ");
    scanf(" %d %d %d %d %d",&sub1,&sub2,&sub3,&sub4,&sub5);
    sum=sub1+sub2+sub3+sub4+sub5;
    per = (sum*100)/500;
    printf("Total marks obtained : %d\n",sum);
    printf("Percentage scored : %.2f\n",per);
    if(per>90){
        printf("Student has passed with grade A.");
    }else if(per>=81 && per<=90){
        printf("Student has passed with grade B.");
    }else if(per>=71 && per<=80){
        printf("Student has passed with grade C.");
    }else if(per>=61 && per<=70){
        printf("Student has passed with grade D.");
    }else if(per>=51 && per<=60){
        printf("Student has passed with grade E.");
    }else if(per>=41 && per<=50){
        printf("Student has passed with grade F.");
    }else{
        printf("Student has failed.");
    }
    return 0;
}


Codes used:
  • #include <stdio.h> : Header file for input output
  • int : integer data type
  • float : Decimal data type
  • sub1, suv2, sub3, sub4, sub5, sum, per : Variables used
  • printf : Function for displaying message
  • scanf : Function for taking input
  • if : Conditional statement
  • else : execute when if statement is false
  • else if : if-else ladder
Do comment, if any doubt
Know about me : Shyam Kanth

No comments:

Post a Comment