这段代码出了什么问题?它应该从我那里得到一个数字,然后显示所有在100&1000000包含该数字。。。
#include <stdio.h>
int main () {
int n,m;
puts("Enter your digit:n");
scanf("%dn", n);
int j=100;
while (j<=1000000) {
m=10;
if (j%m==n) {printf("%dn",j);}
while (j/m>=1) {
if ((j/m)%10==n) {printf("%dn",j);}
m=m*10;}
j+=1;}
return 0;
}
尝试使用此代码,看看它是如何工作的
#include <stdio.h>
#include <math.h>
int main () {
int n,m;
puts("Enter your digit:n");
scanf("%d", &n);
for(int i = 1;(pow(10,i)*n)<1000000;i++)
{
for(int j = 0;j<(pow(10, i));j++)
printf("%lftt", ((pow(10, i)*n))+j);
printf("n");
}
return 0;
}
使用scanf
时,请使用'&'在逗号后面签名。传递一个指向变量的指针,以便scanf
可以存储该值
明智的做法是避免在scanf
内部使用'\n';所以它应该是这样的:
scanf("%d", &n);