2014年3月29日 星期六

反轉字串

#include
#include
#include
int length(char *s)
{   int i;
    for (i=0;*s;i++)s++;
    return i;
}

void revers(char *s)
{
    int i;
    for(i=length(s)-1;i>=0;i--)
    printf("%c",s[i]);  
}
int main(int argc, char *argv[])
{
  char string[50];
  while(scanf("%s",string)!=NULL)
  {  
      revers(string);
      printf("\n");
  }
  system("PAUSE");
  return 0;
}

沒有留言:

張貼留言