Here in this program first we will ask user to enter some numbers and then print the average of those as an output:

Average of list of Numbers

C++:

#include<iostream.h>
#include< conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
int a_num=0, n, num,sum=0;
cout<<"How many numbers you want to enter: ";
cin>>n;
for(int i=1; i<=n;i++)
{
cout<<"Enter number "<<i<<": ";
cin>>num;
a_num++;
sum +=num;
}
cout<<"The average of entered number is: "<<sum/a_num;
getch();
}

Output

How many numbers you want to enter: 5

Enter number 1: 70
Enter number 2: 23
Enter number 3: 34
Enter number 4: 23
Enter number 5: 234
The average of the entered numbers is: 76 

Python:

n = int(input("How many numbers you want to enter: "))
s = 0
an=0
for i in range(1,n+1):
    num = int(input("Enter number "+str(i)+": "))
    s += num
    an +=1
print("The average of the entered numbers is:", s//an)

Output:

How many numbers you want to enter: 4

Enter number 1: 5
Enter number 2: 5
Enter number 3: 5
Enter number 4: 5

The average of the entered numbers is: 5

Leave a Reply

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