Write a program to generate all the jumping numbers less than or equal to a given number
Note: A number is called a Jumping Number if all adjacent digits in it differ by 1. The difference between ‘9’ and ‘0’ is not considered as 1.
Example: 1234, 1012, 9898 are jumping numbers
Input Format
Input contains an integer N
Output Format
Print all the jumping numbers separated by space
Constraint
1<=N<=10^4Sample Input 1
30
Sample Output 1
0 1 2 3 4 5 6 7 8 9 10 12 21 23
Code:
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
int main()
{
int x,i,temp,digit;
bool check;
scanf("%d",&x);
for(i=0;i<=x;i++)
{
if(i<10)
{
printf("%d ",i);
continue;
}
check=1;
temp=i;
digit=temp%10;
temp/=10;
while(temp)
{
if(abs(digit-temp%10)!=1)
{
check=0;
break;
}
digit=temp%10;
temp/=10;
}
if(check)
printf("%d ",i);
}
return 0;
}
Code language: C/AL (cal)