본문 바로가기

C/부스트코스

[부스트코스]알고리즘 퀴즈 3

반응형

Q>

전화번호부와 같이 구조체를 정의하여 관리 및 검색을 하면 더 편리한 예는 또 무엇이 있을까요?

 

A>

#include <cs50.h>
#include <stdio.h>
#include <string.h>

struct Company
{
    int no;
    char name[10];
    char id[10];
    char division[50];
};

int main(void)
{
    struct Company employee1;
    struct Company employee2;

    employee1.no = 12345;
    strcpy(employee1.name, "Ankiwoong");
    strcpy(employee1.id, "ankw");
    strcpy(employee1.division, "contract worker");

    employee2.no = 23456;
    strcpy(employee2.name, "Kimyurim");
    strcpy(employee2.id, "kiyu");
    strcpy(employee2.division, "staff");

    printf("Employee1's employee number is %d.\n", employee1.no);
    printf("Employee1 is named %s.\n", employee1.name);
    printf("Employee1's account ID is %s.\n", employee1.id);
    printf("Employee1 is in %s.\n", employee1.division);

    printf("\n");

    printf("Employee2's employee number is %d.\n", employee2.no);
    printf("Employee2 is named %s.\n", employee2.name);
    printf("Employee2's account ID is %s.\n", employee2.id);
    printf("Employee2 is in %s.\n", employee2.division);
}

 

ex4.c
0.00MB
ex4
0.02MB

 

https://www.boostcourse.org/cs112

 

모두를 위한 컴퓨터 과학 (CS50 2019)

부스트코스 무료 강의

www.boostcourse.org

 

반응형