I started programming and i need help with this problem i do not know what is wrong with it.
/* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.*/
#include <iostream>
using namespace std;
int main()
{
int num;// variable to test values
int sum = 0; //final sum value
int a = 0; // to use for increasing array element
int storage3 [1000];// to hold all of the values that work for 3
int storage5 [1000];//to hold all of the values that work for 5
//Loop to test for multiples of 3
for (num = 0; num < 1000; num++){
int rem3 = num % 3;
if (rem3 == 0) {
num = storage3 [a] ;
}
else{
storage3 [a] = 0;
}
a++;
}
//Loop to test for multiples of 5
for (num = 0; num < 1000; num++) {
int rem5 = num % 5;
if (rem5 == 0) {
num = storage5 [a];
}
else{
storage5 [a] = 0;
}
a++;
}
// loop to sum all numbers
for (int a = 0; a < 1000; a++) {
sum += (storage3 [a] + storage5 [a]);
see what i see is your assign is to just to list out the multiples of 5 and 3
why do yu need to check the no.s from 0-1000 just find the multiples of them
#include <iostream>
usingnamespace std;
int main(int argc, constchar * argv[])
{
constint SIZE(1000);
int numbers[SIZE] = {0};
for (int n=3; n < SIZE; n+=3)
numbers[n] = 1;
for (int n = 5; n < SIZE; n+=5)
numbers[n] = 1;
for (int n = 1; n < SIZE; ++n)
if (numbers[n])
cout << n << endl;
return 0;
}