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;
}




4 comments:

Anonymous said...

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

Anonymous said...

Why did we use %.2f?

Laxman Bista said...

you may get the result like 23.4345343. In this you may like to have two digits after 23 like 23.43 . So %.2f will bring only two digits after 23 and %.3f will bring 3 digits after 23.

sravani said...

how it'll work with array...
can u please provide the code