Problem statement:- Program to Print the average marks obtained by a student in five tests.
Data requirement:-
Input Data:- arr
Output Data:-avg
Output Data:-avg
Additional Data:- i, j, sum
Program in C
Here is the source code of the C Program to Print the average marks obtained by a student in five tests.
Code:
#include<stdio.h>
int main()
{
double arr[5],avg,sum=0.0;
int i=0,j=0;
printf("Enter the five test Marks:\n");
while(i<5)
{
scanf("%lf",&arr[i]);
i++;
}
while(j<5)
{
sum+=arr[j];
j++;
}
avg=sum/5.0;
printf("Average of five tests marks is: %0.2lf",avg);
}
Enter the five test Marks:
95 88 77 45 69
Average of five tests marks is: 74.80
Program in C++
Here is the source code of the C++ Print the average marks obtained by a student in five tests.
Code:
#include<iostream>
using namespace std;
int main()
{
double arr[5],avg,sum=0.0;
int i=0,j=0;
cout<<"Enter the five test Marks:\n";
while(i<5)
{
cin>>arr[i];
i++;
}
while(j<5)
{
sum+=arr[j];
j++;
}
avg=sum/5.0;
cout<<"Average of five tests marks is: "<<avg;
}
Enter the five test Marks:
45 68 95 30 66
Average of five tests marks is: 60.8
Program in Java
Here is the source code of the Java Program to Print the average marks obtained by a student in five tests.
Code:
import java.util.Scanner;
public class p2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double avg,sum=0.0;
double arr[]=new double[5];
int i=0,j=0;
System.out.print("Enter the five test Marks:\n");
while(i<5)
{
arr[i]=sc.nextDouble();
i++;
}
while(j<5)
{
sum+=arr[j];
j++;
}
avg=sum/5.0;
System.out.println("Average of five tests marks is: "+avg);
sc.close();
}
}
Enter the five test Marks:
95 88 75 40 65
Average of five tests marks is: 72.6
Program in Python
Here is the source code of the Python Program to Print the average marks obtained by a student in five tests.
Code:
arr=[]
sum=0
avg=0.0
print("Enter the five test Marks:")
for i in range(0,5):
mark = int(input())
sum+=mark
arr.append(mark)
avg=sum/5.0
print("Average of five tests marks is: ",avg)
Enter the five test Marks:
55
71
64
42
48
Average of five tests marks is: 56.0
Most Recommend Questions:-
More Questions:-
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box