C语言无法连续输入
题目:
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
我的代码:
我试了一下 输入一个数字答案是对的,但是输入一个,回车,再输入一个,回车,程序就报错退出了,这是为什么呢?
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;
}
我试了一下 输入一个数字答案是对的,但是输入一个,回车,再输入一个,回车,程序就报错退出了,这是为什么呢?
...全文
相关推荐
C语言多输入
C语言怎么样多次输入,如何多次输入,不间断。适合c语言的初学者用!
C语言指针简化教学思考.pdf
C语言指针简化教学思考.pdf
C语言转义字符实例详解
里主要介绍了C语言的转义字符的知识,并附有示例代码,以便理解,希望对学习 C语言的同学有所帮助
c语言_源代码如何让解一元三次方程
根的c 语言程序[4]. # include <math.h> main() {float a,b,c,d; float xo x1,x2,f0 f1,f2; printf("请输入方程系数 a,b,c,d;"); scanf("%f,%f,%f,%f",&a,&b,&c,&d"); do {printf("请输入变量的有效范围 x1,x2:"); }while(f1*f2>0); do {x0=(x1+x2)/2; f0=a*x0*x0*x0+b*x0*x0+c*x0+d; if( else {x1=x0;f1=f0;} }while(fabs(f0)>=1e-5); loop:printf("方程的根 x=%f\n",x0); }
利用C语言实现2048小游戏的方法
2048是比较流行的一款数字游戏,相信对大家来说都不陌生,这篇文章给大家分享了利用C语言实现2048小游戏的方法,对大家学习理解C语言具有一定的参考借鉴价值,有需要的朋友们下面来一起看看吧。


