C/C++ 使用一維陣列反轉字串。
範例碼(一):
// ConsoleApplication1.cpp : 定義主控台應用程式的進入點。
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(void)
//or
//int main()
{
int i, j;
char q[50] = { 0 };
char a[50] = { 0 };
printf("輸入字串:");
gets(q);
for (j = 0, i = strlen(q) - 1; i >= 0; j++, i--)
{
a[j] = q[i];
printf("%c", a[j]);
}
printf("\n");
puts(a);
system("pause");
return 0;
}
執行結果:
文章標籤
全站熱搜

留言功能已依作者設定調整顯示方式