본문 바로가기
정보과학

reverse

by chaechaekim 2019. 8. 30.
#include<stdio.h>

void reverse(char a[], int s, int d) {
	if(s<d) {
		char t;
		t = a[d];
		a[d] = a[s];
		a[s]=t;
		reverse(a, s+1, d-1);
	} 
}

int main()
{
	int b, d;
	char c[100];
	printf("문자열을 입력하세요:");
	scanf("%s", c); 
	printf("바꿀 처음 위치와 마지막 위치를 입력해주세요:");
	scanf("%d %d", &b, &d); 
	reverse(c, b, d);
	printf("%s\n", c);
}

/*

문자열을 입력하세요:abcd
바꿀 처음 위치와 마지막 위치를 입력해주세요:0 3
dcba

--------------------------------
Process exited after 4.552 seconds with return value 0
계속하려면 아무 키나 누르십시오 . . .

*/

'정보과학' 카테고리의 다른 글

bmp 이미지 프로세싱  (0) 2019.08.31
recur  (0) 2019.08.30
피보나치 수열  (0) 2019.08.30
n까지의 합(상향식 재귀)  (0) 2019.08.23
n까지의 합(하향식 재귀)  (0) 2019.08.23

댓글