這裏是我的代碼:Int Array []打印不好。
#include <stdio.h>
void main()
{
int indeks, a[11], j, rezultat[50];
int n = 0;
printf("Unesite elemenate niza\n");
while (n < 10)
{
for(indeks = 0; indeks < 10; indeks++);
scanf("%d", &a[indeks]);
n++;
}
for (n = 0; n < 10; n++) {
printf("%d\n", a[n]);
}
}
您好,我有問題,這並不打印陣列,我在輸入一個整數。
它總是打印出-858993460十次。
這是它在cmd中的外觀。 (抱歉不好英語)
Unesite elemenate niza:
1 /input starts here
3
5
1
0
2
3
5
7
4 /ends here
-858993460
-858993460
-858993460
-858993460
-858993460
-858993460
-858993460
-858993460
-858993460
-858993460 /output result
Press any key to continue . . .
您在循環中有一個循環,而在第二個循環的主體中有分號。這意味着** all **您輸入的數據最終在陣列的位置「10」處結束。 – dasblinkenlight 2015-04-01 16:27:12
在for後面加上分號(indegs = 0; indeks <10; indeks ++);'**投票以打印錯誤的方式關閉** – dasblinkenlight 2015-04-01 16:27:37
[main()返回一個int](http://isocpp.org/wiki/ faq/newbie#main-returns-int) – NathanOliver 2015-04-01 16:31:09