BlackWolfy

Longest word (String)

Feb 4th, 2023
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     string word[20];
  6.     string longest;
  7.     cout << "How many words do you wish to check: ";
  8.     int n;
  9.     cin >> n;
  10.     for (int i = 0; i < n;i++) {
  11.         cout << "Enter a word: "<<endl;
  12.         cin >> word[i];
  13.         int min = 1;
  14.         if (word[i].length() > min) {
  15.             min = word[i].length();
  16.             longest = word[i];
  17.         }
  18.     }
  19.     cout << "Longest word is: "<<longest;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment