在线编译器 C

#include <stdio.h> int main() { int n,save_n; scanf("%d",&n); save_n=n; for(int digit=0 ;digit<=9;digit++) { n=scanf; int count_digit=0; while(n>0){ int current_digit==n%10; n/=10; if(current==digit) counter++; n/=10 } if(counter>=2) { printf("%d", digit); } } return 0; }
这段代码试图统计一个整数中每个数字(0-9)出现的次数,并输出出现次数大于等于2的数字。但代码中有多个语法错误和逻辑问题。

- 第8行 `n=scanf;` 是错误的,`scanf` 是一个函数,不能这样赋值。这里应该恢复 `n` 为原始值 `save_n`。
- 第10行 `int current_digit==n%10;` 使用了 `==`(比较运算符)而不是 `=`(赋值运算符),这会导致编译错误。
- 第12行 `n/=10` 重复了,而且第11行已经有一次 `n/=10`,这会导致跳过数字。
- 第13行 `if(current==digit)` 中的 `current` 变量未定义,应该是 `current_digit`。
- 第13行 `counter++` 中的 `counter` 变量未定义,应该是 `count_digit`。
- 第12行末尾缺少分号。

提示:
- 在循环内部,每次检查一个数字时,需要将 `n` 重置为原始值 `save_n`,而不是使用 `scanf`。
- 注意变量名的拼写一致性,比如 `count_digit` 和 `counter` 要统一,`current_digit` 和 `current` 也要一致。