1번
#include < stdio.h>
void main()
{
int nMonth, nCheck;
printf("달을 입력하세요 : ");
scanf("%d", &nMonth);
nCheck = nMonth > 0 ? (nMonth <= 12 ? ((nMonth < 7) ? 0 : 1) : -1 ) : -1;
if(nCheck == -1)
printf("달의 범위가 아닙니다.\n");
else if(nCheck == 0)
printf("상반기\n");
else
printf("하반기\n");
}
2번
#include < stdio.h>
void main()
{
int nNumber, nCheck;
printf("정수를 입력하세요 : ");
scanf("%d", &nNumber);
nCheck = nNumber % 2 == 0 ? 0 : 1;
if(nCheck == 0)
printf("짝수입니다.\n");
else
printf("홀수입니다.\n");
}
3번
#include < stdio.h>
void main()
{
int a, b, c, max;
printf("정수를 입력하세요 : ");
scanf("%d %d %d", &a, &b, &c);
max = (a>b) ? ((a>c) ? a : c) : ((b>c) ? b : c);
printf("가장 큰 수는 %d입니다.\n", max);
}
5번
#include < stdio.h>
void main()
{
int a, b[32]={0,}, i=31, temp;
printf("정수를 입력하세요 : ");
scanf("%d", &a);
while(a!=0)
{
temp = a % 2;
a /= 2;
b[i] = temp;
i--;
}
for(i=0; i<32; i++)
printf("%d", b[i]);
printf("\n");
}