#include <stdio.h>

int main() {
    int bus1 = 10;
    int bus2 = 20;
    int bus3 = 30;

    printf("1번 버스에는 %d명이 타고 있습니다.\n", bus1);
    printf("2번 버스에는 %d명이 타고 있습니다.\n", bus2);
    printf("3번 버스에는 %d명이 타고 있습니다.\n", bus3);

    //배열 선언하기
    int bus[3];
    bus[0] = 10;
    bus[1] = 20;
    bus[2] = 30;
    printf("1번 버스에는 %d명이 타고 있습니다.\n", bus[0]);
    for(int i=0;i<3;i++){
        printf("%d번 버스에는 %d명이 타고 있습니다.\n", i+1, bus[i]);
    }
    

    //배열의 크기는 상수이여야 한다.
    const int size = 10;
    int array[size];

    //배열 초기화하기
    int arr[10] = {10, 12, 23, 42, 22, 52, 0, 8, 9, 45};
    for(int i=0; i<10; i++){
        printf("%d\n", arr[i]);
    }

    //배열에 쓰레기 값이 들어가는 경우
    int arr2[10];
    for(int i=0; i<10; i++){
        printf("%d\n", arr2[i]);
    }

    //일부만 초기화하기
    int arr3[10] = {1, 2};
    for(int i=0; i<10; i++){
        printf("%d\n", arr3[i]);
    }

    //배열 선언과 초기화할 때 크기를 지정하지 않아도 된다.
    int arr4[] = {1, 2, 3};
    
    //실수형 배열 초기화하기
    float arr_f[5] = {1.2 , 3.6, 0, 0, 0};
    for(int i=0;i<5;i++){
        printf("%.1f\n", arr_f[i]);
    }
    
}

Embed on website

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