Answer to Question #216029 in C++ for qwe

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


1
Expert's answer
2021-07-16T01:04:18-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS