Problem statement:- Program to enter marks of five subjects and calculate total, average, and percentage.
Data requirement:-
Input Data:-sub1,sub2,sub3,sub4,sub5
Output Data:-total_marks,avg,percentage
Output Data:-total_marks,avg,percentage
Program in C
Here is the source code of the C Program to enter marks of five subjects and calculate total, average, and percentage.
Code:
#include<stdio.h>
int main(){
double sub1,sub2,sub3,sub4,sub5,total_marks,avg,percentage;
printf("Enter marks of 5 subjects out of 100:");
scanf("%lf %lf %lf %lf %lf",&sub1,&sub2,&sub3,&sub4,&sub5);
total_marks=sub1+sub2+sub3+sub4+sub5;
avg=total_marks/5.0;
percentage=(total_marks/500)*100;
printf("Total Marks: %0.2lf",total_marks);
printf("\nAverage: %0.2lf",avg);
printf("\nPercentage: %0.2lf",percentage,"%");
}
Input/Output:
Enter marks of 5 subjects out of 100:
98
70
63
83
44
Total Marks: 358.00
Average: 71.60
Percentage: 71.60
98
70
63
83
44
Total Marks: 358.00
Average: 71.60
Percentage: 71.60
Program in C++
Here is the source code of the C++ Program to enter marks of five subjects and calculate total, average, and percentage.
Code:
#include<iostream>
using namespace std;int main()
{
double sub1,sub2,sub3,sub4,sub5,total_marks,avg,percentage;
cout<<"Enter marks of 5 subjects out of 100:";
cin>>sub1>>sub2>>sub3>>sub4>>sub5;
total_marks=sub1+sub2+sub3+sub4+sub5;
avg=total_marks/5.0;
percentage=(total_marks/500)*100;
cout<<"Total Marks: "<<total_marks;
cout<<"\nAverage: "<<avg;
cout<<"\nPercentage: "<<percentage<<"%";
}
Input/Output:
Enter marks of 5 subjects out of 100:
88
99
100
55
77
Total Marks: 419
Average: 83.8
Percentage: 83.8%
88
99
100
55
77
Total Marks: 419
Average: 83.8
Percentage: 83.8%
Program in Java
Here is the source code of the Java Program to enter marks of five subjects and calculate total, average, and percentage.
Code:
import java.util.Scanner;
public class FiveSubject {public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double sub1,sub2,sub3,sub4,sub5,total_marks,avg,percentage;
System.out.println("Enter marks of 5 subjects out of 100:");
sub1=cs.nextDouble();
sub2=cs.nextDouble();
sub3=cs.nextDouble();
sub4=cs.nextDouble();
sub5=cs.nextDouble();
total_marks=sub1+sub2+sub3+sub4+sub5;
avg=total_marks/5.0;
percentage=(total_marks/500)*100;
System.out.println("Total Marks: "+total_marks);
System.out.println("Average: "+avg);
System.out.println("Percentage: "+percentage+"%");
cs.close();
}
}
Enter marks of 5 subjects out of 100:
78
87
97
59
79
Total Marks: 400.0
Average: 80.0
Percentage: 80.0%
78
87
97
59
79
Total Marks: 400.0
Average: 80.0
Percentage: 80.0%
Program in Python
Here is the source code of the Python Program to enter marks of five subjects and calculate total, average, and percentage.
Code:
print("Enter marks of 5 subjects out of 100:")
sub1=float(input("Enter sub1 marks:"))sub2=float(input("Enter sub2 marks:"))
sub3=float(input("Enter sub3 marks:"))
sub4=float(input("Enter sub4 marks:"))
sub5=float(input("Enter sub5 marks:"))
total_marks=sub1+sub2+sub3+sub4+sub5;
avg=total_marks/5.0;
percentage=total_marks/500*100;
print("Total Marks:",total_marks)
print("Average:",avg)
print("Percentage:",percentage,"%")
Input/Output:
Enter marks of 5 subjects out of 100:
Enter sub1 marks:92
Enter sub2 marks:32
Enter sub3 marks:64
Enter sub4 marks:25
Enter sub5 marks:69
Total Marks: 282.0
Average: 56.4
Percentage: 56.39999999999999 %
Most Recommend Questions:-
More Questions:-
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box