So i am making a program that will find the multiples of 3 and 5 under 1000. Then it will store all the multiples to an array. The final result is to add together all the values in the array and print it out. Here is my code so far.
NSMutableArray *sums = [NSMutableArray arrayWithCapacity:25];
int a,b,i;
for (i = 0; i <= 1000; i++){
a = i%3;
b = i%5;
if (a==0 || b==0){
[sums addObject:[NSNumber numberWithInteger:i]];
}
}
NSLog(@"\nThe sum of all the multiples of 3 and 5 between 1 and 1000 is %i", );
My question is: How can I add together all the values I have stored in the array “sums”?
1 Answer