3 include stdio h include stdlib h define
실습 3 • 문제정의 – 로그인 시 제한된 횟수만큼 틀리면 로그인 시도를 막는 프로그램을 작성 하시오. #include <stdio. h> #include <stdlib. h> #define SUCCESS 1 #define FAIL 2 #define LIMIT 3 int check(int id, int password); printf("로그인 성공n"); return 0; } int check(int id, int password) { static int 이용 변수선언(super_id/super_pw/try_count) int main(void) { int id, password, result; while(1) { } 사용자로부터 아이디 입력받기 사용자로부터 패스워드 입력받기 result = check(id, password); if( result == SUCCESS ) break; } 횟수 초과여부 } if( id == super_id && password == super_password ) return SUCCESS; else return FAIL;
실습 3 • 소스 코드 #include <stdio. h> #include <stdlib. h> #define SUCCESS 1 #define FAIL 2 #define LIMIT 3 int check(int id, int password); int check(int id, int password) { static int super_id = 1234; static int super_password = 5678; static int try_count = 0; int main(void) { int id, password, result; } while(1) { printf("id: ____bb"); scanf("%d", &id); printf("pass: ____bb"); scanf("%d", &password); result = check(id, password); if( result == SUCCESS ) break; } printf("로그인 성공n"); return 0; } try_count++; if( try_count >= LIMIT ) { printf("횟수 초과n"); exit(1); } if( id == super_id && password == super_password ) return SUCCESS; else return FAIL;
- Slides: 14