試撰寫一函數 void reverse(char str[]),它可將字串 str 反序印出來。舉例來說,輸入的 字串為"Hello",輸出即為"olleH"。
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
void reverse(char str[]); | |
int main(int argc, char *argv[]) | |
{ | |
char str[50]; | |
printf("請輸入一個字串: "); | |
gets(str); | |
reverse(str); | |
system("PAUSE"); | |
return 0; | |
} | |
void reverse(char str[]){ | |
int i=0,j=0; | |
while(str[i]!='\0'){ | |
i++; | |
} | |
printf("轉換後的字串: "); | |
for(j=i-1;j>=0;j--){ | |
printf("%c",str[j]); | |
} | |
printf("\n"); | |
} |
文章標籤
全站熱搜