Загрузка...

Помогите с задачей пж

Тема в разделе C/C++ создана пользователем LoxaEboy 16 дек 2022. 284 просмотра

  1. LoxaEboy
    LoxaEboy Автор темы 16 дек 2022 6 28 дек 2019
    Напишите программу, которая запрашивает n-количество чисел, затем запрашивает ввод n-натуральных чисел. Программа должна вывести на экран в отдельных строках количество и сумму чётных введенных чисел, оканчивающихся на 4.
     
  2. алвейсванафлай
    алвейсванафлай 16 дек 2022 Заблокирован(а)
    C

    #include <iostream>

    int main() {
    // Ask the user for the number of numbers to enter
    std::cout << "Enter the number of numbers: ";
    int n;
    std::cin >> n;

    // Initialize variables to store the sum and count of even numbers ending in 4
    int sum = 0;
    int count = 0;

    // Read in the numbers
    for (int i = 1; i <= n; i++) {
    std::cout << "Enter number " << i << ": ";
    int num;
    std::cin >> num;

    // Check if the number is even and ends in 4
    if (num % 2 == 0 && num % 10 == 4) {
    // Add the number to the sum
    sum += num;
    // Increment the count
    count++;
    }
    }

    // Display the results
    std::cout << "Number of even numbers ending in 4: " << count << std::endl;
    std::cout << "Sum of even numbers ending in 4: " << sum << std::endl;

    return 0;
    }
     
  3. vtlstolyarov
    vtlstolyarov 16 дек 2022 468 8 янв 2022
    Все числа которые оканчиваются на 4 - четные
     
Top
Загрузка...