int
형이라고 가정할 때, 다음 각 변수의 값은 얼마인가?a
: 30
b
: 27
c
: x = 1
, y = 1
d
: x = 3
, y = 9
int
형이라고 가정할 때, 다음 각 변수의 값은 얼마인가?a
: 6
b
: 52
c
: 0
d
: 13
a
: 3.75
b
: 1.5
c
: 35
d
: 37.5
e
: 35.0
#include <stdio.h>
int main(void)
{
int i = 1;
float n;
printf("조심해! 한 무더기의 소수점을 가진 수들이쏟아진다!\n");
while (i < 30) {
n = 1.0f / i++;
printf("%f ", n);
}
printf("\n이제 끝이다!\n");
return 0;
}
sec
의 값을 초기화하지 않았으므로 어떤 결과가 발생할지 알 수 없다. while
문이 실행 안될 수도 있다.
%s! C는 멋지다!
! C는 멋지다!
11
11
12
11
SOS: 4 4.00
1 2 3 4 5 6 7 8 9 10
8.
의 프로그램이 문자 a
부터 g
까지 출력하도록 수정하라. 문자 테이블로 ASCII
를 사용하고 있거나, 알파벳 a
부터 g
까지의 문자가 선형적으로 배치 되어 있는 시스템에서만 정상적으로 동작한다.
#include <stdio.h>
#define TEN 10
int main(void)
{
int n = 0;
char chr = 'a';
while (n++ < TEN)
printf("%5d", n);
while (chr <= 'g')
printf("%5c", chr++);
printf("\n");
return 0;
}
a
1 2
b
101
102
103
104
c
stuvw
COMPUTER BYTES DOG
COMPUTER BYTES DOG
COMPUTER BYTES DOG
... <이하 동문>
a
x = x + 10;
b
x = x + 1;
c
c = (a + b) * 2;
d
c = a + b * 2;
a
x = x - 1;
b
m = n % k;
c
p = q / (b - a);
d
x = (a + b) / (c * d);
#include <stdio.h>
int main(void)
{
double time;
int hour, minute;
scanf("%lf", &time);
hour = (int) time;
minute = ((time - (double) hour) * 100.0) / 100 * 60;
printf("hour: %d minute: %d\n",
hour, minute);
return 0;
}
#include <stdio.h>
int main(void)
{
int start, end;
scanf("%d", &start);
end = start + 5;
while (start <= end)
printf("%-5d", start++);
putchar('\n');
return 0;
}
#include <stdio.h>
int main(void)
{
int days;
int weeks;
scanf("%d", &days);
weeks = 0;
while (days > 7) {
weeks++;
days = days - 7;
}
printf("%d주, %d일\n", weeks, days);
return 0;
}
#include <stdio.h>
#define CENTI_PER_INCH 0.393
#define CENTI_PER_FEET 0.032
int main(void)
{
double height, feet, inch;
printf("센티미터 단위로 키를 입력하시오: ");
scanf("%lf", &height);
while (height > 0.0) {
feet = height * CENTI_PER_FEET;
inch = height * CENTI_PER_INCH;
printf("%.1f 센티미터는 %.0f피트, %.1f인치입니다.\n",
height, feet, inch);
printf("센티미터 단위로 키를 입력하시오(끝내려면 <= 0): ");
scanf("%lf", &height);
}
printf("안녕!\n");
return 0;
}
#include <stdio.h>
int main(void)
{
int count, sum, times;
count = 0; sum = 0;
scanf("%d", ×);
while (count++ < times)
sum = sum + count;
printf("합 = %d\n", sum);
return 0;
}
#include <stdio.h>
int main(void)
{
int count, sum, times;
count = 0; sum = 0;
scanf("%d", ×);
while (count++ < times)
sum = sum + (count * count);
printf("합 = %d\n", sum);
return 0;
}
#include <stdio.h>
float cube(float n)
{
return n * n * n;
}
int main(void)
{
float number;
scanf("%f", &number);
printf("%f\n", cube(number));
return 0;
}
#include <stdio.h>
int main(void)
{
int op1, op2;
printf("이 프로그램은 모듈러스(두 수를 나눈 나머지)를 "
"구하는 프로그램이다.\n");
printf("두 번째 피연산자로 제공할 정수를 입력하시오.: ");
scanf("%d", &op2);
printf("이제 첫 번째 피연산자를 입력하시오.: ");
scanf("%d", &op1);
while (op1 > 0) {
printf("%d %% %d = %d\n", op1, op2, op1 % op2);
printf("첫 번째 피연산자(<= 0 이면 종료) 용 "
"다음 수를 입력하시오.: ");
scanf("%d", &op1);
}
printf("종료\n");
return 0;
}
#include <stdio.h>
void Temperatures(double fahr)
{
const double ABS_TEMP = 273.16;
const double FAHR_PER = 5.0 / 9.0;
const double FAHR_DIF = 32.0;
double celc;
double abs;
celc = FAHR_PER * (fahr - FAHR_DIF);
abs = celc + ABS_TEMP;
printf("섭씨온도: %.2f\n", celc);
printf("절대온도: %.2f\n", abs);
}
int main(void)
{
double celc, fahr;
int ret;
printf("화씨 온도: ");
ret = scanf("%lf", &fahr);
while (ret == 1) {
Temperatures(fahr);
printf("화씨 온도(q 입력 시 종료): ");
ret = scanf("%lf", &fahr);
}
printf("종료\n");
return 0;
}