objective c - How to add a sum of numbers that end in a specific number -


first of sorry if english poor.i tried searching answer dilema without success 2 hours.i imagine question rather easy guys, started out programmin.

so using x code/objective c im trying add numbers 1 500 numbers end in 7.for example : 7,17,27 , on.i want numbers added up.

what have :

int main(int argc, const char * argv[]) {     int  sum = 0 ;      (int = 0; <= 500; i++) {         if (i%10 == 7) {             sum = sum +i;         }     }      nslog(@"total sum is:%i", sum);      return 0; } 

the change make is...

for (int = 7; <= 500; += 10) {     sum += i; } 

this speed sum factor of 10.

of course, can use arithmetic progression single equation.


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 -