-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnofive.c
51 lines (37 loc) · 929 Bytes
/
nofive.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
/*
nofive.c
CodeWars exercise:
In this kata you get the start number and the end number of a region
and should return the nr of all numbers except numbers with
a 5 in it. The start and the end number are both inclusive!
Examples:
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12
The result may contain fives. ;-)
The start number will always be smaller than the end number.
Both numbers can be also negative!
*/
#include <stdio.h>
#include <string.h>
int dontGiveMeFive(int start, int end);
int main(){
int i;
//dontGiveMeFive(4,17);
//dontGiveMeFive(4,29);
//dontGiveMeFive(-30,17);
i = dontGiveMeFive(1,90);
printf("%d\n",i);
return 0;
}
int dontGiveMeFive(int start, int end){
int nr;
int c=0;//counter
char buff[50];
for(nr=start;nr<=end;nr++ ){
sprintf(buff,"%d",nr);
if(!strchr(buff,'5')) c++;
}
return c;
}
/* end of nofive.c */