In this, we will accept 5 subjects marks from the user and calculate its average.

C++:

#include<iostream.h>
#include< conio.h>
#include<math.h>

void main()
{
clrscr();
int math, phy, chem, eng,cs;
float avg;
cout<<"Enter math marks: ";
cin>>math;
cout<<"Enter physics marks: ";
cin>>phy;
cout<<"Enter chemistry marks: ";
cin>>chem;
cout<<"Enter english marks: ";
cin>>eng;
cout<<"Enter cs marks: " ;
cin>>cs;
avg = (math+phy+chem+eng+cs)/5;
cout<<"The average marks you got is: "<<avg;
getch();
}

Output

Enter math marks: 96
Enter physics marks: 87
Enter chemistry marks: 95
Enter english marks: 95
Enter cs marks: 90
The average marks you got is: 92.6

Python

math =int(input("Enter math marks: "))
phy =int(input("Enter physics marks: "))
chem =int(input("Enter chemistry marks: "))
eng =int(input("Enter english marks: "))
cs =int(input("Enter cs marks: ")) 
avg = (math+phy+chem+eng+cs)/5
print("The average marks you got is:",avg)

Output

Enter math marks: 96
Enter physics marks: 87
Enter chemistry marks: 95
Enter english marks: 95
Enter cs marks: 90
The average marks you got is: 92.6

Leave a Reply

Your email address will not be published. Required fields are marked *