By GokiSoft.com| 14:49 23/09/2020|
Lập Trình C

[Share Code] Tìm hiểu struct trong C - Lập trình C



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef int SO_NGUYEN;
typedef char KY_TU;

typedef struct Student_ST {
	char name[30], address[100], rollno[12];
	int age;
} Student;

typedef struct Animal_ST {
	char name[30];
	int age;
} Animal;

int main(int argc, char *argv[]) {
	int x = 5;//D
	SO_NGUYEN k = 10;
	KY_TU c = 'A';
	
	printf("\nK = %d", k);
	
	//Khai bao thong tin sinh vien va dong vat
	//Cach su dung => Student_ST => nhu la 1 kieu du lieu int, char.
//	struct Student_ST std;
	Student std;
	
	//Nhap thong tin sinh vien
	printf("\nNhap ten: ");
	gets(std.name);
	printf("\nNhap tuoi: ");
	scanf("%d", &std.age);
	
	printf("\nTen: %s, tuoi: %d", std.name, std.age);
	
	//khai bao 1 mang gom 5 sinh vien
	Student studentList[5];
	
	int i;
	for(i=0;i<5;i++) {
		printf("\nNhap sinh vien thu %d", i);
		printf("\nNhap ten: ");
		gets(studentList[i].name);
		printf("\nNhap tuoi: ");
		scanf("%d", &studentList[i].age);
	}
	
	return 0;
}




Tags:

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)