C/문법
[C언어] goto 문
BillnairK
2017. 5. 10. 00:20
* goto 문은 말 그대로 해당 레이블로 이동하는 구문이다. *
#include<stdio.h> int main(void) { int num; printf("1 ~ 3 사이의 수를 입력하세요.\n"); scanf_s("%d", &num); if (num == 1) goto one; else if (num == 2) goto two; else if (num == 3) goto three; else goto other; one: printf("입력한 수는 1 입니다."); goto end; two: printf("입력한 수는 2 입니다."); goto end; three: printf("입력한 수는 3 입니다."); goto end; other: printf("1 ~ 3 사이의 수만 입력하세요."); goto end; end: getchar(); getchar(); } |