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;
}

執行結果:

2016-05-08_172315  

arrow
arrow
    文章標籤
    [反轉字串][C++]
    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()