objective c - Calculate the sum of numbers between 1 and 100 that end in 5 -
i'm trying calculate sum of numbers between 1 , 100, numbers end in 5: 5, 15, 25, , on.
i have no idea how this; know how calculate sum, not how deal "ends in 5" condition.
here's have far
int sum = 0; (int = 1; <= 100; i++) { sum = sum +i; } nslog(@"%i", total);
you don't need loops solve this:
int sum1 = 5 * 20 * 21 / 2; // find sum of multiples of 5 int sum2 = 10 * 10 * 11 / 2; // find sum of multiples of 10 int sum = sum1 - sum2; // remove multiples of 10
Comments
Post a Comment