Exemple en langage C - Utilisation des structures (struct)
Utiliser une struct pour stocker les informations d'un étudiant.
Exemple
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
} s;
int main()
{
printf("Saisir les informations :\n");
printf("Nom :");
scanf("%s", s.name);
printf("Numéro :");
scanf("%d", &s.roll);
printf("Score :");
scanf("%f", &s.marks);
printf("Afficher les informations :\n");
printf("Nom :");
puts(s.name);
printf("Numéro : %d\n",s.roll);
printf("Score : %.1f\n", s.marks);
return 0;
}
Le résultat de sortie est:
输入信息: 名字: example 编号: 123 成绩: 89 显示信息: 名字: example 编号: 123 成绩: 89.0autres extensions