Question Number 179571 by Ar Brandon last updated on 30/Oct/22
$$\mathrm{Find}\:\mathrm{the}\:\mathrm{sum}\:\mathrm{of}\:\mathrm{all}\:\mathrm{positive}\:\mathrm{even} \\ $$$$\:\mathrm{3}-\mathrm{digits}\:\mathrm{numbers}\:\mathrm{divisible}\:\mathrm{by}\:\mathrm{17}. \\ $$
Commented by Ar Brandon last updated on 30/Oct/22
#include <stdio.h>
int main(void)
{
short sum = 0;
for (short i = 102; i < 1000; i += 17)
if (i % 2 == 0)
sum += i;
printf("%hd", sum);
return 0;
}
Commented by Ar Brandon last updated on 30/Oct/22
With C programming I get 14688.
Any mathematical solution, please?
Commented by JDamian last updated on 30/Oct/22
▪︎▪︎▪︎; i+= 34)
sum+=i;
as the numbers to sum are multiple of 34. And it is an AP.
Commented by AST last updated on 30/Oct/22
$$\left({i}\:\%\:\mathrm{2}\:==\:\mathrm{0}\right) \\ $$
Commented by Ar Brandon last updated on 30/Oct/22
OK sir you're right. When we add 17 to 102 we get an odd number. When we add 17 again to this last we get an even number. Then we add 17 again and get an odd number and then an even number. So instead of adding 17 and testing if it's even or not, we rather eliminate the test and add 17 twice, that is 34, since adding 17 twice always gives an even number in this case. Well thought Sir JDamien
Commented by Beginner last updated on 02/Nov/22
$${which}\:{program}\:{is}\:{this}? \\ $$