diff options
Diffstat (limited to 'qna')
-rw-r--r-- | qna/gggg123.c | 29 | ||||
-rw-r--r-- | qna/subproc.c | 4 | ||||
-rw-r--r-- | qna/아픈뜸부기_a.c | 34 | ||||
-rw-r--r-- | qna/아픈뜸부기_b.c | 37 |
4 files changed, 104 insertions, 0 deletions
diff --git a/qna/gggg123.c b/qna/gggg123.c new file mode 100644 index 0000000..b776e4e --- /dev/null +++ b/qna/gggg123.c @@ -0,0 +1,29 @@ +#include <stdio.h> + +int main() + +{ + int x, y, z; //정수 변수 정의 + scanf("%d %d %d", &x, &y, &z); //x, y, z 입력 + int xh, yh, zh; //각 변수의 백의 자리수에 대한 변수 정의 + xh = x/100; //x 백의 자리수 + yh = y/100; //y 백의 자리수 + zh = z/100; //z 백의 자리수 + + char ch[3]; + + // 각 수의 백의 자리수가 모두 같으면 T + ch[0] = 'T' * (xh == yh && yh == zh); + // 두 수의 백의 자리수만 같으면 D + ch[1] = + 'D' * + (ch[0] == 0) * /* 근데 모두 같으면 출력하면 안 됨 */ + (xh == yh || yh == zh || zh == xh); + // 백의 자리수가 모두 다르면 S + ch[2] = 'S' * (xh != yh && yh != zh && zh != xh); + + //T,D,S를 입력받는 변수 ch를 정의하고 각 조건에 맞는 문자를 대입(조건이 거짓이면 0을 곱해서 무효처리) + printf("%c%c%c\n", ch[0], ch[1], ch[2]); //ch 출력 + + return 0; +} diff --git a/qna/subproc.c b/qna/subproc.c new file mode 100644 index 0000000..160492d --- /dev/null +++ b/qna/subproc.c @@ -0,0 +1,4 @@ +#include <stdio.h> + + +int main
\ No newline at end of file diff --git a/qna/아픈뜸부기_a.c b/qna/아픈뜸부기_a.c new file mode 100644 index 0000000..4022b8d --- /dev/null +++ b/qna/아픈뜸부기_a.c @@ -0,0 +1,34 @@ +#define _CRT_SECURE_NO_WARNING // https://blog.hcmc.studio/73 +#include <stdio.h> + +int main (void) { + int n, num; + int sum = 0; + int a, b, c, d; + + printf("4자리 정수를 입력하시오: "); + scanf("%d", &n); + num = n; + printf("\n"); + + a = n % 1000 % 100 % 10; + printf("\tn = %4d --> 일의 자리값 --> %d \n", n, a); + n = n % 1000; + + b = n / 10 % 10; + printf("\tn = %4d --> 십의 자리값 --> %d \n", n, b); + n = n / 100; + + c = n % 100 % 10; + printf("\tn = %4d --> 백의 자리값 --> %d \n", n, c); + n = n % 10; + + d = n % 10; + printf("\tn = %4d --> 천의 자리값 --> %d \n", n, d); + n = n % 10; + + sum = d + c + b + a; + printf("n = %4d --> %d + %d + %d + %d = %d \n", num, a, b, c, d, sum); + + return 0; +} diff --git a/qna/아픈뜸부기_b.c b/qna/아픈뜸부기_b.c new file mode 100644 index 0000000..808100a --- /dev/null +++ b/qna/아픈뜸부기_b.c @@ -0,0 +1,37 @@ +#define _CRT_SECURE_NO_WARNING // https://blog.hcmc.studio/73 +#include <stdio.h> + +int main (void) { + static const char *STR_ARR[] = { + "일", + "십", + "백", + "천", + }; + static const size_t STR_ARR_LEN = sizeof(STR_ARR) / sizeof(const char*); + + int n, num; + int sum = 0; + int h[STR_ARR_LEN]; + + printf("4자리 정수를 입력하시오: "); + scanf("%d", &n); + num = n; + printf("\n"); + + for (size_t i = 0; i < STR_ARR_LEN; i += 1) { + h[i] = n % 10; + sum += h[i]; + + printf("\tn = %4d --> %s의 자리값 --> %d \n", n, STR_ARR[i], h[i]); + n /= 10; + } + + printf("\nn = %4d --> ", num); + for (size_t i = 0; i < STR_ARR_LEN; i += 1) { + printf("%d %c ", h[i], i + 1 == STR_ARR_LEN ? '=' : '+'); + } + printf("%d\n", sum); + + return 0; +} |