C program to find average and percentage of marks in five different subjects.





C program to find average and percentage of marks in five different subjects.

#include<stdio.h>
int main(){

    //declaration of variables.
    int science,math,arts,economics,english;
    float total,avg,percentage;

    //accepting marks from user in each subject
    printf("Enter the maks obtained in science,math,arts");
    printf("\n,economics and english respectively : ");
    scanf("%d%d%d%d%d",&science,&math,&arts,&economics,&english);

    //calculatin sum of marks obtained in each subject
    total = science + math + arts + economics + english;

    //calculating the average marks
    avg = total/5;

    //printing the average mark
    printf("Average of marks is : %.3f",avg);

    //calculating the percentage of marks
    percentage = (total*100)/500;

    //printing the percentage of marks in console window
    printf("\nPercentage of marks is : %.2f",percentage);

    return 0;
}




2 comments:

  1. A simple and good logic...........

    ReplyDelete
  2. Why did we use %.2f?

    ReplyDelete