我是初学者。好吧,我只是在尝试数据结构,但不明白为什么会出现错误。我认为发布代码和我得到的输出会更好。(我使用 C-Free 4.0 编译器),顺便说一下。所以这是代码
// 编写一个 C 程序来输入和显示数组的元素
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[44],n,i=0;
// No. of elements:
printf("\n How many elements in all?");
scanf("%d",&n);
// Entering all elements:
printf("\n\n Plz do enter the elements:");
for(;i<n;i++)
scanf("%d",&a[i]);
// Displaying all elements:
printf("\n Array elements are:");
for(i=0;i<n;)
{
printf("\n a[%d]=%d",i,a[i]);
i++;
break;
}
int sum=0;
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("\nSum=%d",sum);
return 0;
}
/*
And here's the output when I say that I'm entering 3 elements into the array:
How many elements in all?3
Plz do enter the elements:12
0
-22
Array elements are:
a[0]=12
Sum=-10Press any key to continue . . . */
大家可以看到,我可以输入值 for(i=0;i