C Language Example - Using Structures (struct)

C Language Examples

Use a struct to store student information.

Example

#include <stdio.h> struct student { char name[50]; int roll; float marks; } s; int main() { printf("Input information:\n"); printf("Name:"); scanf("%s", s.name); printf("Number:"); scanf("%d", &s.roll); printf("Score:"); scanf("%f", &s.marks); printf("Display information:\n"); printf("Name:"); puts(s.name); printf("Number: %d\n",s.roll); printf("Score: %.1f\n", s.marks); return 0; }

The output result is:

输入信息:
名字: example
编号: 123
成绩: 89
显示信息:
名字: example
编号: 123
成绩: 89.0

C Language Examples

other extensions