求一个程序,能显示出全是4和7的数,或者是约数全是4和7的数.
譬如,4,7,16=4x4,28=4x7,44,47,49=7x7,64=4x4x4;74,77等等.我用vc08编译之后总是不对,显示不如16等等.
code:
#include<stdio.h>
int bonheur(int n){
while(n!=0){
if(n%10==4||n%10==7){
n=n/10;
}
else {
return 0;
}
}
while(n>1){
if (n/4==0) n=n/4;
else {
if(n/7==0) n=n/7;
else {
return 0;
}
}
}
return 1;
}
int main(){
int n,m;
printf("donner n est:\n");
scanf("%d",&n);
printf("donner m est:\n");
scanf("%d",&m);
int i;
for(i=n;i<m;i++){
if(bonheur(i)==1){
printf("%d\n",i);
}
}
return 0;
}