Advertisement
khaiwen1111

Tutorial 9 Part B Question 2 & 3

Apr 6th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7.     char word [31];                             //for Q3, change to -> char sentence[51]
  8.     cout << "Enter a word: ";                   //for Q3 change word to sentence
  9.     cin >> word;                                //for Q3, change to -> cin.get(sentence, 51)
  10.    
  11.     int len = strlen(word);                     //for Q3, change word to sentence
  12.     cout << "The word printed backwards: ";     //for Q3, change word to sentence
  13.     for(int i = len -1; i >= 0; i++)
  14.         cout << word[i];                        //for Q3, change word to sentence
  15.     cout<<endl;
  16.  
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement