@C언어 : Layer7
구조체 예제
화이노
2018. 5. 15. 21:13
<구조체 예제>
세 명의 정보를 입력받아 출력
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> typedef struct student { int num; char name[10]; char tell[15]; int age, money; }Student; int main() { Student s1[3]; for (int i = 0; i < 3; i++) { printf("번호 입력 :"); scanf("%d", &s1[i].num); printf("이름 입력 :"); scanf("%9s", s1[i].name); printf("전화번호 입력 :"); scanf("%14s", s1[i].tell); printf("나이 입력 :"); scanf("%d", &s1[i].age); printf("연봉 입력 :"); scanf("%d", &s1[i].money); } printf("번호 \t 이름 \t 전화번호 \t 나이 \t 연봉\n"); for (int i = 0; i < 3; i++) { printf("%d \t %s \t %s \t %d \t %d\n", s1[i].num, s1[i].name, s1[i].tell, s1[i].age,s1[i].money); } system("pause"); return 0; } | cs |