Write a C++ program to create a new string with the last char added at the front and back of a given string of length 1 or more

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to create a new string with the last char added at the front and back of a given string of length 1 or more

Sample Output:

dRedd
nGreenn
111

الأجوبة

#include <iostream>
using namespace std;

string test(string str)
        {
            string s = str.substr(str.length()-1);
            return s + str + s;
        }
        
int main() 
 {
  cout << test("Red") << endl;  
  cout << test("Green") << endl;  
  cout << test("1") << endl;  
  return 0;    
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...