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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -