Answers for "c program to right shift a string by 2 numbers"

C++
1

c program to right shift a string by 2 numbers

/*c,cpp program to right shift a string by n positions
(may be 1right, 2right, etc.)*/
#include <string>
using namespace std;
void main()
{
	string str="apple";
    int shift;
    cout<<"Enter the number of shifts for the string to get shifted: ";
    cin>>shfit;
    int n=str.length();
    for(int i=n+2;i>=shift;i--){
        str[i]=str[i-shift];
    }
    //now the string is shifted by 'shift' positions "right".
}
Posted by: Guest on July-13-2021

Code answers related to "c program to right shift a string by 2 numbers"

Browse Popular Code Answers by Language