W rite a program to compute the sum of the int e gers that divisible by 4 from 10…
- User
W rite a program to compute the sum of the int e gers that divisible by 4 from 10 different integers (using DO/WHILE loop and FOR loop) .
- Assistant
Here is a program that computes the sum of integers divisible by 4 using a
do/whileloop and aforloop:using System;
namespace SumOfIntegersDivisibleBy4 { class Program { static void Main(string[] args) { //using do/while loop int sumDoWhile = 0; int countDoWhile = 0;
code - User
باc++
- Assistant
Certainly! Here is the equivalent C++ program that computes the sum of integers divisible by 4 using a do/while loop and a for loop:
cpp#include <iostream> using namespace std; int main() { // Using do/while loop int sumDoWhile = 0; int countDoWhile = 0; cout << "Using do/while loop:" << endl; do { cout << "Enter an integer: "; int num; cin >> num; if (num % 4 == 0) { sumDoWhile += num; countDoWhile++; } } while (countDoWhile < 10); cout << "Sum of integers divisible by 4 using do/while loop: " << sumDoWhile << endl; // Using for loop int sumFor = 0; cout << "\nUsing for loop:" << endl; for (int i = 0; i < 10; i++) { cout << "Enter an integer: "; int num; cin >> num; if (num % 4 == 0) { sumFor += num; } } cout << "Sum of integers divisible by 4 using for loop: " << sumFor << endl; return 0; }