C/perpect C
3장 연습문제와 형식지정자
옥식
2021. 12. 24. 18:02
01.
#include <stdio.h>
int main(void)
{
printf("%d %d", 021, 0x1b);
return 0;
}
결과
02.
#include <stdio.h>
int main(void)
{
int point1 = 88, point2 = 92;
int total = point1 + point2;
printf("중간: %d 기말: %d 합: %d\n", point1, point2, total);
return 0;
}
결과
03.
#include <stdio.h>
int main(void)
{
printf("%d %d %d\n", 8, 010, 0x8);
printf("%d %d %d\n", 9, 011, 0x9);
printf("%d %d %d\n", 10, 012, 0xa);
printf("%d %d %d\n", 11, 013, 0xb);
printf("%d %d %d\n", 12, 014, 0xc);
printf("%d %d %d\n", 13, 015, 0xd);
printf("%d %d %d\n", 14, 016, 0xe);
printf("%d %d %d\n", 15, 017, 0xf);
return 0;
}
결과
04.
#include <stdio.h>
int main(void)
{
printf("%c %c %c %c %c\n", '^', '*', '!', '#', '@');
printf("%f %f %f\n", 10.63, 2.34567E3, 2.34567E-3);
printf("\"C\" 언어는 재미있는 \'프로그래밍 언어\'이네요.\n");
return 0;
}
결과
05.
#include <stdio.h>
#define PI 3.14//매크로 상수
int main(void)
{
double radious = 5.37;
printf("원 반지름: %f\n", radious);
printf("원 면적: %f\n", radious * radious * PI);
printf("원 둘레: %f\n", 2 * radious * PI);
return 0;
}
결과
06.
#include <stdio.h>
int main(void)
{
printf("%c", '\a'); //알람울림
printf("%s", "수업시간 입니다.");
return 0;
}
결과
07.
#include <stdio.h>
int main(void)
{
printf("%c %c %c %c %c", 041, 042, 043, 044, 045);
return 0;
}
결과
08.
#include <stdio.h>
int main(void)
{
double const p = 3.305785;
printf("18평: %f제곱미터\n", 18 * p);
printf("25평: %f제곱미터\n", 25 * p);
return 0;
}
결과
09.
#include <stdio.h>
int main(void)
{
double const km = 0.621371;
printf("60km: %fmile\n", 60*km);
printf("80km: %fmile\n", 80*km);
printf("100km: %fmile\n", 100*km);
printf("120km: %fmile\n", 120*km);
return 0;
}
결과
10.
#include <stdio.h>
int main(void)
{
printf("%c ", 'A' + 2);
printf("%c ", 'A' + 5);
printf("%c ", 'S' - 1);
printf("%c ", 'S' - 3);
return 0;
}
결과
11.
#include <stdio.h>
int main(void)
{
long long stm = 117900000, stc = 2871000000;
printf("화성과 천왕성 가느이 거리 = %lld km\n", stc-stm);//long long의 형식지정자 %lld
return 0;
}
결과
12.
#include <stdio.h>
#define EXCHANGE_RATE 1120.0
int main(void)
{
int won = 1000000;
printf("1000000원 => %f달러 \n", won / EXCHANGE_RATE);
return 0;
}
결과
참고 C언어 형식지정자