#include < stdio.h >#include < string.h >void main(void){ char word1[10]; char word2[10]; int w1_Length,w2_Length; int i,j=0; char temp[10]; printf("enter word1:"); scanf("%s", &word1); printf("enter word2:"); scanf("%s", &word2); w1_Length = strlen(word1); w2_Length = strlen(word2); for(i=w1_Length-1; i>=0; i--) { if(word1[i] == word2[w2_Length-1]) { w2_Length--; temp[j] = word1[i]; //printf("%c", temp[j]); j++; }else { break; } } temp[j] = '\0'; printf("\"%s\"以及\"%s\"的最大相似尾巴是\"%s\"", word1, word2, strrev(temp)); printf("\n");}
張貼留言
1 則留言:
#include < stdio.h >
#include < string.h >
void main(void)
{
char word1[10];
char word2[10];
int w1_Length,w2_Length;
int i,j=0;
char temp[10];
printf("enter word1:");
scanf("%s", &word1);
printf("enter word2:");
scanf("%s", &word2);
w1_Length = strlen(word1);
w2_Length = strlen(word2);
for(i=w1_Length-1; i>=0; i--)
{
if(word1[i] == word2[w2_Length-1])
{
w2_Length--;
temp[j] = word1[i];
//printf("%c", temp[j]);
j++;
}else
{
break;
}
}
temp[j] = '\0';
printf("\"%s\"以及\"%s\"的最大相似尾巴是\"%s\"", word1, word2, strrev(temp));
printf("\n");
}
張貼留言