본문 바로가기
C언어

[C언어] 숫자, 대문자, 소문자를 섞어서 비밀번호를 만드는 프로그램을 작성하시오.

by 이얏호이야호 2022. 12. 14.

공부하시는대에 도움이 됐으면 좋겠습니다.

답안코드 확인해주세요!

 

더보기
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	int is_upper, is_lower, is_digit;
	char password[30];


	while (1) {
		printf("암호를 생성하시오: ");
		scanf(" %s", password);

		is_upper = is_lower = is_digit = 0;
		for (i = 0; i < strlen(password); i++)
		{
			if (password[i] >= '0' && password[i] <= '9')
				is_digit = 1;
			else if (password[i] >= 'A' && password[i] <= 'Z')
				is_upper = 1;
			else if (password[i] >= 'a' && password[i] <= 'z')
				is_lower = 1;
		}

		if ((is_digit == 1) && (is_upper == 1) && (is_lower == 1)) {
			printf("적정한 암호. \n");
			break;
		}
		else
			printf("숫자, 소문자, 대문자를 모두 사용해서 작성하시오\n");
	}
	return(0);
}

 


더 많은 C코드가 보고 싶다면?

https://chuinggun.tistory.com/category/C%EC%96%B8%EC%96%B4

댓글