//-------------------------------------------------------------------- // backword.cpp //--------------------------------------------------------------------
// Displays the letters in a word in reverse order.
#include <iostream.h>
const int MAX_SIZE = ; // Max word size of five, allow for '\0'
void reverse ( char word[] );
void main() { char word[ ]; // Array storing a word
cout << endl << "Enter a word, five letters or less: "; cin >> word; reverse(word); }
void reverse ( char word[] ) { int i, lastCharPos = 0; // Index of last letter in word
// Find the end of the word. while ( word[lastCharPos] != '\0') lastCharPos++;
// Display the word backwards. cout << "The word written backwards is: "; for ( i = strlen(word) ; i > 0; i-- ) cout << word[i]; cout << endl; }