反转数组的内容

Inverting the array's content

所以有人告诉我用 c++ 编写一个程序,用户输入一个单词,我必须将它插入一个数组,但问题是当我必须反转单词时:

#include <iostream>

using namespace std;

const int EOS = '.';
const int MAX = 30;

typedef char VectorC[MAX];

void showInversion (char word[MAX],int n)
{
    for (int i = n; i <= n-1 ; i--){
        cout << word[i];
    }
}
int main()
{
   VectorC word;
   char c = 'a';
   int i = 0, n = 0;

   cout << "ENTER SEQUENCE:" << endl;

   while (c!=EOS){
       word[i] = c = cin.get();
       i++;
       n++;   //length of the word
   }
   cout << "THE RESULT IS: " << showInversion(word,n);

   return 0;
}

输出示例:

输入一个序列:

计算机。

结果是:RETUPMOC

要打印倒序,简单的方法就是将word中的字符从头到尾打印出来。

void showInversion (char word[MAX],int n)
{
    for (int i = n - 1; i >= 0 ; i--){
        cout << word[i];
    }
}