-
Notifications
You must be signed in to change notification settings - Fork 0
/
week 4 in c
62 lines (46 loc) · 1.09 KB
/
week 4 in c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<1> Sum of Digits of a Five Digit Number
Task
Given a five digit integer, print the sum of its digits.
Input Format
The input contains a single five digit number, .
Output Format
Print the sum of the digits of the five digit number.
Sample Input 0
10564
Sample Output 0
16
#include <stdio.h>
int main(){
int num = 58612;
int sum = 0;
while(num != 0){
sum += num % 10;
num = num/10;
}
printf("Digit sum: %d", sum);
}
<2> Count Divisors 7
You have been given 3 integers - l, r and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count.
Input Format
The first and only line of input contains 3 space separated integers l, r and k.
Constraints
1<=l<=r<=1000 1<=k<=1000
Output Format
Print the required answer on a single line.
Sample Input 0
1 10 1
Sample Output 0
10
#include <stdio.h>
int main()
{
int l,r,k,i=0,count=0;
scanf("%d %d %d",&l,&r,&k);
for(i=l;i<=r;i++)
{
if(i%k==0)
count++;
}
printf("%d",count);
return 0;
}