#include <stdio.h>
int main() {
/* 자료형과 서식 지정자
정수 int %d
실수 float (4바이트) %f
double (8바이트) %lf
문자형 char
문자 %c ''
문자열 %s ""
*/
int i = 2025;
printf("정수 %d\n", i);
float f = 9.237;
printf("실수 %f\n", f);
printf("소수 둘째 자리까지 출력 %.2f\n", f);
double d = 3.123456789123456;
printf("실수 %.15lf\n", d);
printf("소수 셋째 자리까지 출력 %.3lf\n", d);
char c = 'a';
printf("문자 %c\n", c);
char s[] = "abc";
printf("문자열 %s\n", s);
//문자열의 가장 마지막에는 널null문자 \0이 들어있다
printf("%d\n", sizeof(s));
printf("----문제----\n");
// 1. char 타입 변수에 문자 'C'를 저장해서 출력하세요.
char ch = 'C';
printf("1 : %c\n", ch);
// 2. 문자열 "Hello C"를 저장한 뒤, 그 길이를 sizeof 연산자를 이용해 출력하세요.
char str[] = "Hello C";
printf("2 : 문자열:%s, 문자열 길이:%d\n", str, sizeof(str));
// 3. float 타입 변수에 소수 둘째 자리까지 출력할 수 있는 값을 저장하고 출력하세요.
float f1 = 3.14159f;
printf("3 : %.2f\n", f1);
// 4. double 타입 변수에 긴 소수를 저장하고 소수점 15자리까지 출력하세요.
double d1 = 1.123456789;
printf("4 : %.15lf\n", d1);
// 진법
// 이진수 bin : 0b, 0B
int a1 = 0b1101;
printf("%d\n", a1);
// 8진수 oct : 0
int b1 = 012;
printf("%d\n", b1);
// 16진수 hex : 0x, 0X
int c1 = 0x1A;
printf("%d\n", c1);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: