元素逆置

将一个数组中的元素逆置

#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

int main()
{
    char a[]="hello world";
    int n=strlen(a);
    char b;
    for(int i=0;i<n/2;i++)
    {
      b=a[i];
      a[i]=a[n-i-1];
      a[n-i-1]=b;
    }
    puts(a);
    return 0;
}

 

posted @ 2016-08-02 09:46  多思考&&多动手  阅读(336)  评论(0编辑  收藏  举报