Tuesday 24 June 2014

C++ program to rotate a string


Here is a C++ program to rotate a string


 SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str[100],temp;
    int lenght;
    cout<<"Enter string : ";
    cin>>str;
    lenght=strlen(str);
    cout<<"Rotating string : "<<endl;
    for(int i=0;i<lenght;i++)
    {
        cout<<str<<endl;
        temp=str[0];
        for(int y=0;str[y+1]!='\0';y++)
            str[y]=str[y+1];
        str[lenght-1]=temp;
    }
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment