PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to input marks of five subjects and calculate percentage and grade according to following data

Input - Output

Input
Enter marks of five subject : 70 85 69 81 74

Output
Grade : B

Input
Enter marks of five subject : 60 54 40 61 24

Output
Grade : Fail

Algorithm

Step 1: START

Step 2: Input marks of five subject which store in variable like eng,hindi,math,sci and comp

Step 3: Calculate sum of all five subject as total with this formula :

    total = eng+hindi+math+sci+comp

Step 4: Calculate percentage with this formula P = (total / 500) * 100

Step 5: Calculate grade using these condition :

    if(per>90 && per<=100) then grade A+

    else if(per>80 && per<=90) then grade A

    else if(per>70 && per<=80) then grade B

    else if(per>60 && per<=70) then grade C

   else if(per>50 && per<=60) then grade 'Pass'

    else then grade "fail"

Step 6: END

CODE


/* Calculate Percentage and Grade */

#include <stdio.h>
int main()
{
      int english,hindi,math,science,computer,total;
      float per;
      printf("Enter the marks of five subjects : ");
      scanf("%d%d%d%d%d",&english,&hindi,&math,&science,&computer);
      total = english + hindi + math + science + computer;
      per= (total*100)/500;
      printf("\n percentage = %.2f \n",per);
      if(per>90 && per<=100)
        printf("Grade : A+");
      else if(per>80 && per<=90)
        printf("Grade:= A");
      else if(per>70 && per<=80)
        printf("Grade : B");
      else if(per>60 && per<=70)
        printf("Grade : C");
      else if(per>=50 && per<=60)
        printf("Grade : Pass");
      else
        printf("Grade : Fail");
    return 0;
}


/* Calculate percentage anf Grade*/

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
      int english,hindi,math,science,computer,total;
      float per;
      cout<<"Enter the marks of five subjects : ";
      cin>>english>>hindi>>math>>science>>computer;
      total = english + hindi + math + science + computer;
      per= (total*100)/500;
      cout<<"\n percentage = "<< fixed << setprecision(2)<<per<< endl;
      if(per>90 && per<=100)
        cout<<"Grade : A+";
      else if(per>80 && per<=90)
        cout<<"Grade : A";
      else if(per>70 && per<=80)
        cout<<"Grade : B";
      else if(per>60 && per<=70)
        cout<<"Grade : C";
      else if(per>=50 && per<=60)
        cout<<"Grade : Pass";
      else
        cout<<"Grade : Fail";
    return 0;
}

OutPut

Enter marks of five subject : 70 85 69 81 74

Grade : B