"C언어 문자열 뒤집기"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 2개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;C언어 문자열 뒤집기
;C언어 문자열 뒤집기
<source lang='c'>
<syntaxhighlight lang='c' run>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
int main() {
int main() {
     char s[5] = "hello";
     char s[6] = "hello";
     int i, j, temp;
     int i, len, temp;
     for (i=0, j=strlen(s)-1; i<j; i++, j--) {
    len = strlen(s);
     for (i=0; i<len/2; i++) {
         temp = s[i];
         temp = s[i];
         s[i] = s[j];
         s[i] = s[len-i-1];
         s[j] = temp;
         s[len-i-1] = temp;
     }
     }
     printf("%s\n", s); // olleh
     printf("%s\n", s); // olleh
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2021년 9월 24일 (금) 21:11 기준 최신판

1 개요[ | ]

C언어 문자열 뒤집기
#include <stdio.h>
#include <string.h>
int main() {
    char s[6] = "hello";
    int i, len, temp;
    len = strlen(s);
    for (i=0; i<len/2; i++) {
        temp = s[i];
        s[i] = s[len-i-1];
        s[len-i-1] = temp;
    }
    printf("%s\n", s); // olleh
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}