gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
12 - Write a program c++ to compute the sum of the integers that divisible by 4 from 10…
- User
12
Write a program c++ to compute the sum of the integers that divisible by 4 from 10 different integers (using DO/WHILE loop)
- Assistant
Here's a C++ program that computes the sum of integers divisible by 4 from 10 different integers using the DO/WHILE loop:
#include <iostream> int main() { int count = 0; int sum = 0; int num; // Loop to input 10 integers do { std::cout << "Enter an integer: "; std::cin >> num; // Check if the number is divisible by 4 if (num % 4 == 0) { sum += num; count++; } } while (count < 10); std::cout << "Sum of integers divisible by 4: " << sum << std::endl; return 0; }In this program, we use a
do-whileloop to input 10 integers from the user. If the entered number is divisible by 4 (i.e.,num % 4 == 0), we add it to thesumvariable and increment thecountvariable. Once we have collected 10 integers, the loop exits, and we print the sum of integers divisible by 4.