# 5μ₯ Programming νμ΄
201p_1λ²)
#include <stdio.h>
int main()
{
int num;
printf("μ μλ₯Ό μ
λ ₯νμμ€: ");
scanf_s("%d", &num);
if ((num% 2) == 0)
{
printf("%dλ μ§μμ
λλ€.", num);
}
else
{
printf("%dλ νμμ
λλ€.", num);
}
return 0;
}
201p_2λ²)
#include <stdio.h>
int main()
{
int first, second, tmp;
printf("μ μλ₯Ό μ
λ ₯νμμ€: ");
scanf_s("%d", &first);
printf("μ μλ₯Ό μ
λ ₯νμμ€: ");
scanf_s("%d", &second);
if (first < second)
{
tmp = first;
first = second;
second = tmp;
}
printf("λ μμ ν©μ %dμ
λλ€.", first + second);
printf("λ μμ μ°¨λ %dμ
λλ€.", first - second);
return 0;
}
201p_3λ²)
#include <stdio.h>
int main()
{
int day;
printf("μμΌμ 0(μΌμμΌ)μμ 6κΉμ§μ μ μλ‘ μ
λ ₯νμμ€: ");
scanf_s("%d", &day);
if (day == 0 || day == 6)
{
printf("μ£Όλ§μ
λλ€.");
}
else
{
printf("μ£Όμ€μ
λλ€.");
}
return 0;
}
201p_4λ²)
#include <stdio.h>
int main()
{
char word;
printf("λ¬Έμλ₯Ό μ
λ ₯νμμ€: ");
scanf_s("%c", &word);
if (48 <= word && word <= 57)
{
printf("μ«μμ
λλ€.");
}
else if (65 <= word && word <= 90 || 97 <= word && word <= 122)
{
printf("μνλ²³μ
λλ€.");
}
else
{
printf("νΉμλ¬Έμμ
λλ€.");
}
return 0;
}
+ μ½λ μ°Έκ³
201p_5λ²)
#include <ctype.h>
#include <stdio.h>
int main()
{
char word;
printf("λ¬Έμλ₯Ό μ
λ ₯νμμ€: ");
scanf_s("%c", &word);
if (isupper(word) != 0)
{
printf("λλ¬Έμμ
λλ€.");
}
else
{
printf("μλ¬Έμμ
λλ€.");
}
return 0;
}
202p_6λ²)
#include <stdio.h>
int main()
{
char color;
printf("μ νΈλ±μ μκΉ μ
λ ₯ (R, G, Y): ");
scanf_s("%c", &color);
if (color == 'R' || color == 'r')
{
printf("μ μ§!");
}
else if (color == 'G' || color == 'g')
{
printf("μ§ν");
}
else
{
printf("μ£Όμ");
}
return 0;
}
202p_7λ²)
#include <stdio.h>
int main()
{
int a, b, c;
printf("μΌκ°νμ μΈ λ³μ μ
λ ₯νμμ€: ");
scanf_s("%d%d%d", &a, &b, &c);
if (a + b <= c || b + c <= a || a + c <= b)
{
printf("μΌκ°νμ΄ μλλλ€.");
}
else
{
if (a == b || a == c || c == b)
{
if (a == b && b == c)
{
printf("μ μΌκ°ν");
}
else
{
printf("μ΄λ±λ³ μΌκ°ν");
}
}
else
{
printf("μΌλ° μΌκ°ν");
}
}
return 0;
}
202p_8λ²)
#include <stdio.h>
int main()
{
double stand, earn;
printf("κ³ΌμΈ νμ€μ μ
λ ₯νμμ€(λ§ μ): ");
scanf_s("%lf", &stand);
if (stand > 8000)
{
earn = (1000 * 8 / 100) + (3000 / 100 * 17) + (4000 * 26 / 100) + ((stand - 8000) * 35 / 100);
}
else if (stand < 8000 && stand > 4000)
{
earn = (1000 * 8 / 100) + (3000 * 17 / 100) + ((stand - 4000) * 26 / 100);
}
else if (stand < 4000 && stand > 1000)
{
earn = (1000 * 8 / 100) + ((stand - 1000) * 17 / 100);
}
else
{
earn = stand * 8 / 100;
}
printf("μλμΈλ %.3lfλ§μμ
λλ€.\n", earn);
return 0;
}
203p_9λ²)
#include <stdio.h>
int main()
{
int a, b;
char cal;
printf("μμμ μ
λ ₯νμμ€: ");
scanf_s("%d", &a);
scanf_s(" %c ", &cal);
scanf_s("%d", &b);
switch(cal)
{
case '+':
printf("%d", a + b);
break;
case '-':
printf("%d", a - b);
break;
case '*':
printf("%d", a * b);
break;
case '/':
printf("%d", a / b);
break;
}
return 0;
}
203p_10λ²)
#include <stdio.h>
int main()
{
char grade;
printf("νμ μ μ
λ ₯νμμ€: ");
scanf_s("%c", &grade);
switch (grade)
{
case 'A':
printf("μμ£Ό μνμ΄μ!");
break;
case 'B':
printf("μ’μ΅λλ€.");
break;
case 'C':
printf("λ§μ‘±μ€λ½μ΅λλ€.");
break;
case 'D':
printf("λ λ
Έλ ₯ν΄λ³΄μΈμ.");
break;
case 'F':
printf("μνκΉμ΅λλ€.");
break;
}
return 0;
}