一个刷题系统显示部分正确,请修正🙏
论文问答
1
#include < stdio.h >
int main() {
int i,
m,
n,
flag = 0;
scanf("%d %d", &m, &n);
for (i = m; i <= n; i++) {
if (i % 3 == 0 && (i % 10 == 5 || i / 10 == 5 || i / 100 == 5 || i / 1000 == 5)) {
if (flag == 0) printf("%d", i);
if (flag == 1) printf(" %d", i);
flag = 1;
}
}
if (flag == 0) printf("No exist");
return 0;
}
-
#include <stdio.h> int has_five(int x) { while (x) { if (x % 10 == 5) return 1; x /= 10; } return 0; } int main() { int m, n; scanf("%d%d", &m, &n); int found = 0; for (int i = m; i <= n; i++) { if (i % 3 == 0 && has_five(i)) { if (found) printf(" "); printf("%d", i); found = 1; } } if (!found) printf("No exist"); return 0; }
-
if(i%3==0&&(i%10==5||i/10==5||i/100==5||i/1000==5))这个判断条件不对 例如150这个数,%10=15不等于5,不符合条件,但它是含5的3的倍数
发表回复