How to check if a number is Lucky Number using C++.

 #include <bits/stdc++.h>


using namespace std;


int main (){

int a,b,i,j,digits,f = 0,c=0;

cin >> a >> b;

for(i = a;i<=b;i++){

for(j = i;j>0;j/=10){

digits = j % 10;

f =0;

if(digits!= 4 && digits!= 7){

f++;

break;

}

} if(f == 0){

cout << i <<" ";

c++;

}


}

if(c == 0){

cout << -1 << endl;

}

return 0;

}

Comments