[英]Why is this program exiting the loop without printing any output?
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a, b;
scanf("%d\n%d", &a, &b);
for (int a; a <= b; a++) {
if (a <= 9) {
char* arr[10] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
printf("%s", arr[a - 1]);
}
else if ((a > 9) && (a % 2 == 0)) {
printf("even");
}
else if ((a > 9) && (a % 2 != 0)) {
printf("odd");
}
}
return 0;
}
在上面的程序中,我想打印小于 9 的数字,如果大于 9 应该打印它是旧的还是在 for 循环内。
我是 C 编程的初学者,谁能帮我弄清楚这段代码有什么问题,为什么它退出循环而不给出任何输出。
在其中一个控制台中,我收到以下错误:
Reading symbols from Solution...done.
[New LWP 674234]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./Solution'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
我的数组声明有问题吗?
不要让另一个a
对象。
它隐藏了在int a, b;
声明的更高级别a
int a, b;
.
// for(int a;a<=b;a++){
for( ; a<=b; a++){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.