write a c++ program to find the sum of integers between 1 and 500 except those numbers which are divisible by 7 and 9
#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
Comments
Leave a comment