C言語実例 - 構造体(struct)の使用

C 语言实例C言語実例

構造体(struct)を使用して学生情報を格納します。

実例

#include <stdio.h> struct student { char name[50]; int roll; float marks; } s; int main() { printf("情報を入力:\n"); printf("名前:"); scanf("%s", s.name); printf("番号:"); scanf("%d", &s.roll); printf("成績:"); scanf("%f", &s.marks); printf("情報を表示:\n"); printf("名前:"); puts(s.name); printf("番号: %d\n",s.roll); printf("成績: %.1f\n", s.marks); return 0; }

出力結果は次のとおりです:

输入信息:
名字: サンプル
编号: 123
成绩: 89
显示信息:
名字: サンプル
编号: 123
成绩: 89.0

C 语言实例C言語実例

その他の拡張