C++ Program to Rotates a word
This program prints all the rotation of a word.
Say if the input word is "space", then it prints
>>space
>>paces
>>acesp
>>cespa
>>espac
#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
char w[50],buf[50],temp[50],buf2[10];
clrscr();
printf("Enter a word to see it's rotation :");
fflush(stdin);
gets(w);
strcpy(temp,w);
printf("All the rotation of the word \"%s\" are :",w);
for(int i=0;i<strlen(w);i++)
{
strcpy(buf,strnset(w,' ',i));
for(int j=0;j<i;j++)
buf2[j]=temp[j];
buf2[j]='\0';
strcat(buf,buf2);
//To straighten the output
gotoxy(strlen(w)-i,4+i);
puts(buf);
}
getch();
}
Related Posts : C++ Programs
0 comments:
Post a Comment