What is the sum of all three-digit numbers that are divisible by 5 ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Using Turbo Pascal, we have this following code:
Gives u = 9 8 5 5 0
Java code:
int sum = 0; for(int i = 100; i < 1000; i += 5) { sum += i; } System.out.println(sum);
Python Code
for n in range(99, 1000):
if (n % 10 == 0 or n % 5==0):
sum=sum+n
print sum
why you check for that the no. is divisible by 10
The 3-digit numbers which are divisible by 5 are 1 0 0 , 1 0 5 , 1 1 0 , . . . . . . , 9 9 5 . These numbers are in AP with first term ( a ) = 1 0 0 and common difference ( d ) = 5 . Let a n be last term. So,
a n = 9 9 5 ⟹ a + ( n − 1 ) d = 9 9 5 ⟹ 1 0 0 + ( n − 1 ) 5 = 9 9 5 ⟹ n − 1 = 5 1 0 9 5 = 1 7 9 ⟹ n = 1 8 0
Thus, there are 180 terms in the AP, so we use here the formula of sum of AP, S = 2 n ( a + l ) where l = Last term
So, S = 2 1 8 0 ( 1 0 0 + 9 9 5 ) = 9 0 × 1 0 9 5 = 9 8 5 5 0
Problem Loading...
Note Loading...
Set Loading...