C program, algorithm, flowchart & explanation of the program that accepts marks of 5 subjects and finds the sum and percentage marks obtained by the student.

WAP that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student.

Write a C program that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student:-

Here, we have to write a simple C program that takes marks obtained in different subjects by the user and gives total marks and percentage values as output.

Formula used:-

Percentage= (sum/500)*100

Explanation & Program code:-

We will ask the user to enter the marks of different subjects, then we will store the entered marks in the respective variables. Based on the entered marks of different subjects, we will calculate the total marks and percentage. Further details are mentioned as comments in the program code.

C
#include <stdio.h>
#include <math.h>
int main()
{
    float maths,physics,chemistry,computer,mechanics,sum,per; /* Decleration of variable*/
    printf("Enter marks obtained in Maths:-");
    scanf("%f",&maths);                                     
    printf("Enter marks obtained in Physics:-");
    scanf("%f",&physics);
    printf("Enter marks obtained in Chemistry:-");             /* Taking input from user and storing it to respective variables*/
    scanf("%f",&chemistry);
    printf("Enter marks obtained in Computer:-");
    scanf("%f",&computer);
    printf("Enter marks obtained in Mechanics:-");
    scanf("%f",&mechanics);
    sum=maths+physics+chemistry+computer+mechanics;             /* Calculation of total marks*/
    printf("Total marks:-%.2f\n",sum);
    per=(sum/500)*100;                                         /* Percentage calculation*/
    printf("Percentage:-%.2f",per);                            /*Calculated percentage as Output*/
    return 0;
}

Output:-

C
Enter marks obtained in Maths:-89
Enter marks obtained in Physics:-86
Enter marks obtained in Chemistry:-56
Enter marks obtained in Computer:-89
Enter marks obtained in Mechanics:-97
Total marks:-417.00
Percentage:-83.40

Algorithm of program that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student:-

Step 1:- Start.
Step 2:- Declaration of variables.
Step 3:- Read the marks of 5 subjects and store it to respective variables.
Step 4:- Add all 5 variables that contain marks of subjects and store them to a new variable called sum.
Step 5:- Print sum(Total marks).
Step 6:- Percentage=(sum/500)*100. (Assuming Maximum marks of each subject is 100)
Step 7:- Print Percentage.
Step 8:- Stop.

Flowchart of the program that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student:-

flowchart for the program that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the

As you have reached the end of the article, so I hope as of now you have a clear understanding of the algorithm, flowchart, and program code that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student. Please let me know your queries, suggestion, and feedback in the comment section.

Leave a Comment

Your email address will not be published.