Greetings everyone,
I'm a novice to C++, just started working with it a couple of days ago. I wrote a program that computes the sum of all integers between 1 and 100 that have a remainder of 2 when divided by 3, 5 or by both. Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main() {
int x, div1, div2, result = 0;
for (x = 1; x <= 100; x++) {
div1 = x % 3;
div2 = x % 5;
if (div1 == 2 and div2 == 2 or div1 == 2 or div2 == 2) {
result += x;
}
}
cout << result;
}
Is there a way to enhance this code?
Another question; I have been trying to write a program that prints all the three digit integers that use three distinct digits from a set, ie {1, 2, 3, 4, 5, 6, 7}. It should print 123, 324, 567, 712 but not 773 or 333.
Thanks in advance