首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个容易程序错在哪里了

2013-09-05 
这个简单程序错在哪里了#include stdio.hvoid reverse(unsigned int[] a, int size) {int tempfor(int

这个简单程序错在哪里了


#include <stdio.h>

void reverse(unsigned int[] a, int size) {
    int temp;
    for(int i = 0; i < size/2; i++) {
    temp = a[0];
a[0] = a[size - 1 - i];
a[size - 1 - i] = temp;
    }
}
int main() {
    unsigned int[] a = {1, 2, 3, 4, 5};
    reverse(a, 5);
    for(int i = 0; i < size - 1; i++) {
    printf("%u ", a[i]); 
    }
}


--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.c
C:\Documents and Settings\Administrator\桌面\1.c(3) : error C2146: syntax error : missing ')' before identifier 'a'
C:\Documents and Settings\Administrator\桌面\1.c(3) : error C2061: syntax error : identifier 'a'
C:\Documents and Settings\Administrator\桌面\1.c(3) : error C2059: syntax error : ';'
C:\Documents and Settings\Administrator\桌面\1.c(3) : error C2059: syntax error : ','
C:\Documents and Settings\Administrator\桌面\1.c(3) : error C2059: syntax error : ')'

这么简单的一个程序却编译不成功,我看了半天也没看出来哪里错了,郁闷啊!
[解决办法]
数组写法错了吧
int[] a 
应该是 int a[] 吧。
[解决办法]
帮你修改了下代码, 你看看,可以跑了!

#include <stdio.h>

void reverse(unsigned int a[] , int size) 
{
    unsigned int temp;
    for(int i = 0; i < size/2; i++) {
        temp = a[0];
        a[0] = a[size - 1 - i]; 


        a[size - 1 - i] = temp;   
    }   
}

int main() 
{
    unsigned int a[] = {1, 2, 3, 4, 5}; 
    int size = 5;
    printf("%d ", size); 
    reverse(a, size);
    for(int i = 0; i < size - 1; i++) {
        printf("%u ", a[i]); 
    }   
}

热点排行