这是我的代码:
#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 . . .
最佳答案
for
循环不执行任何操作,因为它以 ;
结尾,并且当 while
循环迭代时,indeks
始终为10
。我建议如下
#include <stdio.h>
int main() // correct function type
{
int indeks, a[11], j, rezultat[50];
int n = 0;
printf("Unesite elemenate niza\n");
//while (n < 10) // delete while loop
//{
for(indeks = 0; indeks < 10; indeks++) // remove trailing ;
scanf("%d", &a[indeks]);
//n++; // delete unnecessary line
//}
for (n = 0; n < 10; n++) {
printf("%d\n", a[n]);
}
return 0; // add return value
}
关于c++ - Int Array[ ] 打印不好。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29395935/