Напишите программу, которая в последовательности натуральных чисел находит среднее арифметическое
двузначных чисел или сообщает, что таких чисел нет (выводит «NO»). Программа получает на вход натуральные числа, количество введённых чисел неизвестно, заканчивается числом 0 (0 последовательность чисел в последовательность). признак окончания ввода, не входит Количество чисел не превышает 100. Введённые числа не превышают 300. Программа должна вывести среднее арифметическое двузначных чисел или вывести «NO», если таких чисел нет. Значение выводить с точностью до десятых. Пример работы программы: Входные данные 10 120 49 0 Выходные данные 29.5 Входные данные 111 1 0 Выходные данные NOОтветы на вопрос
Писал на С#, могу переделать под с++\python при надобности
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirtsCSharp
{
class Program
{
static void Main(string[] args)
{
List<double> numbers = new List<double>();
double l = double.Parse(Console.ReadLine());
while(l != 0)
{
numbers.Add(l);
l = int.Parse(Console.ReadLine());
}
double sum = 0;
sum = numbers.Where(x => x > 9 && x < 100).Sum();
int k = numbers.Where(x=> x>9 && x < 100).Count();
Console.WriteLine(sum == 0 ? "NO" : (sum/k).ToString());
Console.ReadLine();
}
}
}
Program to Find the Average of Two-Digit Numbers
Here's a program in C++ that finds the average of two-digit numbers in a sequence of natural numbers:
```cpp
#include
int main() { int count = 0; int sum = 0; int number;
while (true) { cin >> number; if (number == 0) { break; } if (number >= 10 && number <= 99) { sum += number; count++; } }
if (count > 0) {
float average = static_cast
return 0; } ```
This program takes a sequence of natural numbers as input, with the sequence ending when the number 0 is entered. It checks each number in the sequence and adds it to the sum if it is a two-digit number (between 10 and 99). It also keeps track of the count of two-digit numbers encountered.
After the sequence ends, the program calculates the average of the two-digit numbers by dividing the sum by the count. If there are no two-digit numbers in the sequence, it outputs "NO".
For example, if the input sequence is "10 120 49 0", the program will output "29.5". If the input sequence is "111 1 0", the program will output "NO".
Please note that this program is written in C++. If you need it in a different programming language, let me know and I can provide the code in that language as well.
Let me know if you have any further questions!
Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili
