Q:

Write a C++ program to create a new string using the two middle characters of a given string of even length (at least 2)

0

Write a C++ program to create a new string using the two middle characters of a given string of even length (at least 2)

Sample Output:

el
JS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

string test(string s1)
         {
              return s1.substr(s1.length() / 2 - 1, 2);
         }
         
int main() 
 {
  cout << test("Hell") << endl;  
  cout << test("JS") << endl; 
  return 0;    
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now