2019-01-10

Hyeonu_Chun·2021년 6월 21일

HW28

#pragma warning (disable : 4996)
#include <stdio.h>

int main() {
	char ch;
	int eng = 0, num = 0, escape = 0, rest = 0;
	printf("# 영문 문장을 입력 하시오 :\n");
	while ((ch = getchar()) != EOF){
		if ((ch >= 97 && ch <= 172) || (ch >= 65 && ch <= 90)) {
			eng++;
		}
		else if (ch == 32 || ch == 10 || ch == 9) {
			escape++;
		}
		else if (ch >= 48 && ch <= 57) {
			num++;
		}
		else {
			rest++;
		}
	}
	printf("* 영문자 대소문자 개수 : %d개\n* 숫자문자 개수 : %d개\n* 여백문자(space, tab, enter) 개수 : %d개\n* 그 외 기타문자 개수 : %d개\n", eng, num, escape, rest);
	return 0;
}

HW29

#pragma warning (disable : 4996)
#include <stdio.h>

int inputUInt(const char *);
int transNumber(int);

int main() {
	int count = 0;
	int P1 = inputUInt("시작 값(P1) : ");  
	int P2 = inputUInt("끝 값(P2) : ");
	int N = inputUInt("고집수(N) : ");
	if (P1 >= 100 && P2 <= 10000) {
		if (N >= 1 && N <= 10) {
			printf("고집수가 %d인 숫자 출력\n", N);
			for (int i = P1; i <= P2; i++) {
				int j = 0;
				int res = i;
				while (j+1) {
					if ((res / 10) != 0) { res = transNumber(res); }
					else { break; }
					j++;
				}
				if (j == N) {
					printf("%d\n", i);
					count++;
				}
			}
		}

	}
	printf("총 개수 : %d", count);
	return 0;
}

int inputUInt(const char *str) {
	int num;
	printf("%s", str);
	scanf("%d", &num);
	return num;
}

int transNumber(int num) {
	if (num < 100) {
		int fir = num / 10;
		int sec = num - (fir * 10);
		return fir * sec;
	}
	else if (num < 1000) {
		int fir = num / 100;
		int sec = (num - (fir * 100)) / 10;
		int thr = (num - (fir * 100) - (sec * 10));
		return (fir * sec * thr);
	}
	else if (num < 10000) {
		int fir = num / 1000;
		int sec = (num - (fir * 1000)) / 100;
		int thr = (num - (fir * 1000) - (sec * 100)) / 10;
		int fo = (num - (fir * 1000) - (sec * 100) - (thr * 10));
		return (fir * sec * thr * fo);
	}
	else return 0;
}
profile
Stay hungry, stay foolish

0개의 댓글