Monday 21 November 2016

Program to find GPA using If-else statement

Program to find GPA using IF-ELSE statement:

#include<stdio.h>
int main()
{
  int mark1,mark2,mark3,mark4,mark5,totalmarks,sum;
  float avg,div,per;
  totalmarks=500;
  printf("Enter marks of Subject1 out of 100=");
  scanf("%d",&mark1);
  printf("Enter marks of Subject2 Study out of 100=");
  scanf("%d",&mark2);
  printf("Enter marks of Subject3 out of 100=");
  scanf("%d",&mark3);
  printf("Enter marks of Subject4 out of 100=");
  scanf("%d",&mark4);
  printf("Enter marks of subject5 out of 100=");
  scanf("%d",&mark5);
  printf("Maximum Marks=%d",totalmarks);
  sum=mark1+mark2+mark3+mark4+mark5;
  printf("\nObtained marks=%d",sum);
  avg=sum/5;
  printf("\nAverage=%0.2f",avg);
  per=(sum*100)/500;
  printf("\nPercentage=%0.4f",per);
  if(per>=90 && per<=100)
  {
     printf("\nGPA=4.0");
     printf("\nA+");
  }
  else if(per>=85 && per<=89)
  {
      printf("\nGPA=3.7");
      printf("\nA");
  }
  else if(per>=80 && per<=84)
  {
      printf("\nGPA=3.3");
      printf("\nB+");
  }
  else if(per>=75 && per<=79)
  {
      printf("\nGPA=3");
      printf("\nB");
  }
  else if(per>=70 && per<=74)
  {
      printf("\nGPA=2.7");
      printf("\nB-");
  }
  else if(per>=65 && per<=69)
  {
      printf("\nGPA=2.3");
      printf("\nC+");
  }
  else if(per>=60 && per<=64)
  {
      printf("\nGPA=2.0");
      printf("\nC-");
  }
  else if(per>=55 && per<=59)
  {
      printf("\nGPA=1.7");
      printf("\nD+");
  }
  else if(per>=50 && per<=54)
  {
      printf("\nGPA=1.3");
      printf("\nD-");
  }
  else if(per>=0 && per<50)
  {
      printf("\nGPA=0.0");
      printf("\nF");
  }
  return 0;
  getchar();
}



2 comments: