C++ only.
Must use loops. Please do not use sequence of if statements.
Given as input string and an int N, set result a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive.
• for input of "Hello", 3 → "llollollo"
• for input of "Hello", 2 → "lolo"
• for input of "Hello", 1 → "o"
#include<iostream> using namespace std; int main() { string s; int n; cout<<"Enter a string: "; cin>>s; cout<<"Enter number: "; cin>>n; for(int j = 0;j<n;j++){ for(int i = s.length()-n;i<s.length();i++){ cout<<s[i]; } } return 0; }
Get Answers For Free
Most questions answered within 1 hours.