Write a program that reads two integer numbers X and Y and calculate the sum of all number not divisible by 13 between them, including both.
Input
The input file contains 2 integer numbers X and Y without any order.
Output
Print the sum of all numbers between X and Y not divisible by 13, including them if it is the case.
Input Sample | Output Sample |
100
200 |
13954
|
Solution using C :
#include <stdio.h>
int main() {
int x,y,i,s=0;
scanf("%d%d",&x,&y);
if(x<y)
{
for(i=x; i<=y; i++)
{
if(i%13 != 0)
s += i;
}
}
else
{
for(i=y; i<=x; i++)
{
if(i%13 != 0)
s += i;
}
}
printf("%d\n",s);
return 0;
}
Comments
Post a Comment