CodeSolved

Solved Programming Questions & Exercises

Average numbers (infinite)

Practice Easy 24/ Download 4567 Views Most popular

Write a program that can obtain the average infinite number of numbers:

The program must first get the user's numbers (as long as the user has not entered the number 0, taking the numbers must continue)

Next step must be calculated and printed the mean numbers received and printed

29 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
print("start!!")
s = 0
n = 0
while True:
    i = int(input("Number:")) 
    if i == 0:
        break 
    s += i 
    n += 1 
print("avg:",s / n )   
print("end") 
User 3385 Download Python
def calculate_average():
    numbers = []  # List to save numbers

    while True:
        # Get a number from the user
        number = float(input("لطفاً یک عدد وارد کنید (برای پایان عدد 0 را وارد کنید): "))
        
        # Checking whether the user has entered the number 0
        if number == 0:
            break
        
        # Add the number to the list
        numbers.append(number)

    # Calculating and printing average
    if len(numbers) > 0:
        average = sum(numbers) / len(numbers)
        print("میانگین اعداد وارد شده برابر است با:", average)
    else:
        print("هیچ عددی وارد نشده است.")

# Implementation of the function
calculate_average()
Mma123 Download Python
a = 0
b = 0

while True:
    n = int(input("adad:"))
    if n ==0:
        break
    a = a + n
    b = b + 1   
print(a/b)

F.sarli Download Python
num=int(input("enter a number: "))
sum=0
count=0
while(num!=0):
    sum+=num
    count+=1 
    num=int(input("enter a number: "))
print("avg: ",sum/count)
Saeeda33 Download Python
print(" salam ; baray etmam add giri add  0  ra vared kon ta mieangin ro bede")
mieangin = 0
j = 1
a = float(input("add {} :      ".format(j)))
while a != 0 :
    mieangin = a / j
    j = j + 1
    a = float(input("add {} :      ".format(j)))
    mieangin = (mieangin + a) / j
else:
    print(mieangin)
Esmaeelphy Download Python
s=0
while 1:
 num= int(input('num:'))
 if num==0:
  break
 s+=num
print(s)
Maryam.n Download Python
#include <iostream>
#include <conio.h>
using namespace std;
    main()
{
    int n , i = 0 , m = 0;
    cout << "enter your n: ";
    while (1)
    {
        cin >> n;
        if(n!=0)
        {
        m += n; // 2+0=2+3=5+3=8
        i++; // 2 3 4
        }
        else
            break;
    }
    cout << "miyangin adade varde shode : " <<(double) m / i;
    getch(); 
}

Hamid Download C & C++
<< Previous page 1 2 3 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close