198: Write a C++ program to find the third largest string in a given array of strings.
// Write a C++ program to find the third largest string in a given array of strings.
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter the size of array: ";
cin >> size;
string array[size];
for (int i = 0; i < size; i++)
{
cout << "Enter a string for index " << i << ": ";
getline(cin >> ws, array[i]);
}
system("cls");
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (array[i].length() < array[j].length())
{
string temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
cout << "Thrid largest string is: \n";
cout << array[2] << endl;
return 0;
}
Comments
Post a Comment