#include <iostream>
#include <string>
using namespace std;
int main()
{
string name, name1;
char ch;
cout << "Enter any sentence" << endl; // printing the middle letter
getline(cin, name);
ch = name[name.length()/2];
cout << "The middle letter in the sentence is " << ch << endl;
for (int i = 0; i <= (name.length() / 2)-1; i++) // printing the first half of the sentence
{
cout << name[i];
}
cout << "\nThe second half " << endl;
for (int i = (name.length() / 2 )+1; i <= name.length(); i++) // printing the second half of the sentence
{
cout << name[i];
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter