C语言。使用数组,编写程序完成从键盘顺序输入n个整数,首尾元素相互交换,然后将它们输出。

如题所述

#include<stdio.h>
void main()
{
  int a[50];
  int i=0,j=0;
  int temp;
  printf("请输入数据,中间用空格间隔,用回车结束输入:\n");
  do
  {
    scanf("%d",&a[i++]);
  }while(getchar()()!='\n');
   //首尾交换
   temp =a[0];
   a[0] =a[i-1]
   a[i-1] = temp;
    ///输出
    for(j=0;j<i;j++)
    {
      printf("%3d  ",a[j]);
    }
    printf("\n");
}

///输入的时候这样输入:  1空格2空格3空格4回车

追问

while哪一行 error C2064: term does not evaluate to a function

追答

那换成
while(getchar() !='\n'); 吧

温馨提示:答案为网友推荐,仅供参考