#include <stdio.h>

int main() {
     /* 자료형과 서식 지정자
     정수 int %d
     실수 float (4바이트) %f
         double (8바이트) %lf
     문자 char %c ''
     문자열 char %s ""
     */

     int i = 2025;
     printf("정수 %d\n", i);

     float f = 11.15f;
     printf("실수 %f\n", f);
     printf("소수 둘째 자리까지 출력 %.2f\n", f);

     double d = 3.123456789123456;
     printf("실수 %lf\n", d);
     printf("소수 15번째 자리까지 출력 %.15lf\n", d);

     char c = 'a';
     printf("문자 %c\n", c);

     char s[4] = "abc";
     printf("문자열 %s\n", s);
     // 문자열의 가장 마지막에는 널null문자 \0이 들어있다

     printf("----문제----\n");
     // 1. char 타입 변수에 문자 'C'를 저장해서 출력하세요.
     char c1 = 'C';
     printf("%c\n", c1);

     // 2. 문자열 "Hello C"를 저장한 뒤 출력하세요.
     char s1[] = "Hello C";
     printf("%s\n", s1);

     // 3. float 타입 변수에 소수 둘째 자리까지 출력할 수 있는 값을 저장하고 출력하세요.
     float f1 = 11.42f;
     printf("%.2f\n", f1);

     // 4. double 타입 변수에 긴 소수를 저장하고 소수점 10자리까지 출력하세요.
     double d1 = 1.123456789123456;
     printf("%.10lf\n", d1);

     return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: