目前分類:C/C++ (28)
- Jul 21 Thu 2016 22:18
C語言 a++ 與 ++a的差別
- Jul 05 Tue 2016 00:11
C語言 鏈結串列(link list)的實作範例
- Jun 30 Thu 2016 23:46
C語言動態記憶體配置(Dynamic memory allocation)
- Feb 06 Fri 2015 23:26
C語言 字串翻轉例題
試撰寫一函數 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"); | |
} |
- Jan 09 Fri 2015 19:18
C語言 質數判斷
- Jan 04 Sun 2015 23:12
C語言 do while例題
- Nov 24 Mon 2014 21:29
C語言 華氏攝氏溫度轉換 梯形面積
- Nov 14 Fri 2014 21:30
用C語言寫99乘法表