|
发表于 2012-5-10 08:22:51
|
显示全部楼层
- /*应该没有BUG了,蛋疼的VC6.0,不支持C99,代码改了半天。。。*/
- #include<stdio.h>
- #define SIZE 8
- void swap(int [],int);
- int main(void)
- {
- int a[SIZE];
- int input_success;
- int i=0,h,k;
- printf("Enter the eight(8) integer of a.\n");
-
- while(1)
- {
- input_success=scanf("%d",&a[i]);
- //我就搞不懂这编译器怎么就不能把上面这式子放进while和if的条件判断中
-
- if(input_success)//成功输入一次数据,i自加1
- {
- i++;
- if(i==8)
- break;//成功输入8个数据后,退出循环
- continue;
- }
- else
- {
- printf("input error,enter again.\n");
- while((getchar()!='\n'))//如果输入错误,清除输入缓冲区
- continue;
- }
- }
- printf(" a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]\n");
- for(h=0;h<SIZE;h++)
- printf("%6d",a[h]);
- printf("\n");
- swap(a,SIZE);
- printf("Now!a is this:\n");
- printf(" a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]\n");
-
- for(k=0;k<SIZE;k++)
- printf("%6d",a[k]);
- printf("\n");
- return 0;
- }
- void swap(int arry[],int n)//这个函数没花什么心思,不通用
- {
- int i,j;
- for(i=0,j=n-1;i<4;i++,j--)
- {
- int temp=0;
- temp=arry[i];
- arry[i]=arry[j];
- arry[j]=temp;
- }
- }
复制代码 |
|