C语言无法连续输入

Tomato_Allen Tomato_Allen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
题目:
Input a number N, and do the prime factorization(质因数分解).

The input contains several test cases. Each test case contains exact one integer N.

For each test case, you should output at least one line for the prime factorization of N. For example, if N = 144 = 24 * 32, then you should output two lines for this test case:

2 4

3 2

There should be an empty line between test cases.



Data Promise

For all test cases, 2 <= N <= 105



Sample Input

2

10

144



Sample Output

2 1

2 1
5 1

2 4
3 2


我的代码:
#include<stdio.h>
int main() {
int num, i, j, k = 0, t = 1, test, a[10000] = {0}, b[10000] = {0}, \
m, n, p;
while (scanf("%d", &num) != EOF) {
for (i = 2; i < num; i++) {
t = 1;
for (j = 2; j < i; j++) {
if (i % j == 0) {
t = 0;
break;
}
}
if (t == 1 && num % i == 0) {
a[k] = i;
k++;
}
}
for (m = 0; m < k; m++) {
n = 1;
test = a[m];
while (num % test == 0) {
test *= a[m];
n++;
}
b[m] = n-1;
}
a[k] = b[k] = 0;
k++;
}
for (j = 0; j < k-1; j++) {
if (a[j] == 0) printf("\n");
else printf("%d %d\n", a[j], b[j]);
}
return 0;
}


我试了一下 输入一个数字答案是对的,但是输入一个,回车,再输入一个,回车,程序就报错退出了,这是为什么呢?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
Tomato_Allen
C语言 70,039 成员 243,237 内容