小弟不才 写个小程序出现了点问题 大家帮我看看问题出在哪里

#include<stdio.h>
void main()
{
int a[10],i;
int *p;
printf("please input an array:\n");
for(i=0;i<10;i++)
scanf("%d",a[i]);
p=a;
printf("the order of this array is:\n");
for(i=0;i<10;i++)
printf("%d",*p++);
p=a;
for(i=0;i<5;i++)
{
int temp;
temp=*(p+i);
*(p+i)=*(p+(9-i));
*(p+(9-i))=temp;
}
printf("the right order of this array is:\n");
for(i=0;i<10;i++)
printf("%d",*p++);
}

scanf("%d",a[i]);这句报错。
你要明白scanf()的调用方式:scanf("<格式化字符串>",<地址表>);
这里使用的时候,第二个参数应该是一个地址或者指针,因此要改成scanf("%d",&a[i]);

正确代码如下:
#include<stdio.h>
void main()
{
int a[10],i;
int *p;
printf("please input an array:\n");
for(i=0;i<10;i++)

scanf("%d",&a[i]);

p=a;
printf("the order of this array is:\n");
for(i=0;i<10;i++)
printf("%d ",*p++);
p=a;
for(i=0;i<5;i++)
{
int temp;
temp=*(p+i);
*(p+i)=*(p+(9-i));
*(p+(9-i))=temp;
}
printf("\nthe right order of this array is:\n");
for(i=0;i<10;i++)
printf("%d ",*p++);
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-07-30
for(i=0;i<10;i++)
scanf("%d",&a[i]);
相似回答
大家正在搜