- 1
Using the do-while loop sum all the multiples of 5 between 0 to 100
4 Réponses
+ 9
Easy with mathematics.
int x = 100 / 5;
int ans = (((x) * (x + 1)) / 2) * 5;
Same answer without any loop. This is more efficient algorithm. 😊
+ 6
Spam
- 1
int i=5,sum=0;
do{
sum=sum+i;
i+=5;
}while(i==100);
}
- 1
https://code.sololearn.com/c3U5TOU8QCwX/?ref=app
There you are even a bit more. Unless I misunderstood what you were going for.