Question #216029

write a c++ program to find the sum of integers between 1 and 500 except those numbers which are divisible by 7 and 9


Expert's answer

#include <iostream>

using namespace std;

int main()
{
    int sm = 0, n = 500;
    for (int i = 1; i <= n; i++) {
        if (i%7!=0 && i%9!=0) sm += i;
    }
    cout << "The sum is: " << sm;

    return 0;
}

Output:
The sum is: 95262

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS