Created
November 5, 2013 10:42
-
-
Save Codeplaza/7317142 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*given the length it should print all the repeated strings in the word of that particular length*/ | |
| #include<stdio.h> | |
| #include<conio.h> | |
| int main() | |
| { | |
| int i,j,k,l,p=0,f,q=0,t; | |
| char s[100]; | |
| printf("\nenter the word:"); | |
| gets(s); | |
| textcolor(YELLOW); | |
| cprintf("\nenter the length of the string to be repeated twice:"); | |
| scanf("%d",&f); | |
| textcolor(GREEN); | |
| cprintf("\nThe strings which are repeated are:"); | |
| printf("\n"); | |
| for(i=f;s[i]!='\0';i++) /*it is required to test for repetition from the value of the given length as there can be no repetition before that */ | |
| { | |
| for(j=i-f;j>=q-1;j--) /* comparision of the word must start from the current position -length given.....if matched then check for the next element else decrement j*/ | |
| { | |
| for(k=i,l=j;k<i+f;k++,l++) /*compare two words till the length is equal to the given length*/ | |
| { | |
| if(s[k]==s[l]) | |
| { | |
| p++; | |
| if(p==f) | |
| { | |
| q=l; | |
| textcolor(1+i); | |
| for(t=i;t<i+f;t++) | |
| { | |
| cprintf("%c",s[t]); | |
| } | |
| printf("\n"); | |
| } | |
| } | |
| else | |
| { | |
| k=i;l=j;p=0;break; | |
| } | |
| } | |
| } | |
| } | |
| getch(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment