Загрузка...

Help with the task plz

Thread in C/C++ created by LoxaEboy Dec 16, 2022. 285 views

  1. LoxaEboy
    LoxaEboy Topic starter Dec 16, 2022 6 Dec 28, 2019
    Напишите программу, которая запрашивает n-количество чисел, затем запрашивает ввод n-натуральных чисел. Программа должна вывести на экран в отдельных строках количество и сумму чётных введенных чисел, оканчивающихся на 4.
     
  2. алвейсванафлай
    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
    Все числа которые оканчиваются на 4 - четные
     
Top
Loading...