-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jumping_Numbers.c
75 lines (73 loc) · 1.79 KB
/
Jumping_Numbers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
int check_jumping_num(int num){
int duplicate_num=num;
int flag=0;
int prev_digit,next_digit,curr_digit;
int i=0;
while (num)
{
if (i==0)
{
curr_digit = num%10;
prev_digit=curr_digit;
num=num/10;
next_digit = num%10;
if (curr_digit-next_digit!=1 && curr_digit-next_digit!=-1)
{
flag=1;
return 0;
}
else
{
flag=0;
}
}
else
{
// printf("p is %d\n",prev_digit);
curr_digit = num%10;
// printf("c is %d\n",curr_digit);
num=num/10;
// printf("Num Is %d",num);
next_digit = num%10;
// printf("n is %d\n",next_digit);
if (next_digit==0 && num<10)
{
break;
}
if (curr_digit-prev_digit!=1 && curr_digit-prev_digit!=-1)
{
flag=1;
return 0;
}
else if (curr_digit-next_digit!=1 && curr_digit-next_digit!=-1)
{
flag=1;
return 0;
}
else
{
flag=0;
}
prev_digit=curr_digit;
}
i++;
}
if (flag==0)
{
return 1;
}
}
int main()
{
int x=4343456;
if (check_jumping_num(x))
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}