chapter 17) 최고 학점의 학생 데이터 출력
#include struct student{ int id; char name[20]; double grade; }; int main(void){ struct student s1 = {315, "test1", 2.4}, s2 = {315, "test2", 3.7}, s3 = {317, "test3", 4.4}; struct student max; max = s1; if (s2.grade > max.grade) max = s2; if (s3.grade > max.grade) max = s3; printf("class : %d\n", max.id); printf("name : %s\n", max.name); printf("grade : %.1lf\n", max.grade); return 0; } ### 구조체..
2024. 10. 5.
chapter 17) 구조체 배열을 초기화하고 출력
#include struct address { char name[20]; int age; char tel[20]; char addr[80]; }; int main(void){ struct address list[5] = { {"test1", 23, "111-1111", "core1"}, {"test2", 35, "222-2222", "core2"}, {"test3", 19, "333-3333", "core3"}, {"test4", 15, "444-4444", "core4"}, {"test5", 45, "555-5555", "core5"} }; for( int i= 0; i< 5; i++){ printf("%10s%5d%15s%20s\n", list[i].name, list[i].age, list[i].t..
2024. 10. 4.
chapter 17) 자기 참조 구조체로 list 만들기
#include struct list{ int num; struct list *next; }; int main(void){ struct list a = {10, 0}, b = {20,0}, c = {30,0}; struct list *head = &a, *current; a.next = &b, b.next = &c; printf("head -> num : %d\n", head -> num); printf("head -> next -> num : %d\n", head -> next -> num); printf("list all :"); current = head; while(current != NULL){ printf("%d ", current -> num); current = current -> next..
2024. 10. 3.