#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
我的陣列宣告有問題嗎?
uj5u.com熱心網友回復:
不要做另一個a物件。
它隱藏了較高水平a的宣告int a, b;。
// for(int a;a<=b;a ){
for( ; a<=b; a ){
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/350293.html
上一篇:并排粘貼檔案
下一篇:如何按字母順序排列連接的列
