1 //----------------------------1
2 #include<stdio.h>
3 #define N 5
4 struct student
5 {
6 int num;
7 char name[10];
8 float score;
9 };
10
11 void main()
12 {
13 int i;
14 struct student stu[N],*p;
15 p=stu;
16 printf("input information:\n");
17 printf("学号,姓名,成绩:\n");
18 /*格式描述符\t表示跳到下一个tab的位置,
19 就相当于在DOS环境下按tab键
20 。%4.lf中的数字4表示输出的实数共有4位(包括小数点),
21 数字1表示小数点后保留1位
22 */
23 for(i=0;i<N;i++)
24 scanf("%d%s%f",&stu[i].num,stu[i].name,&stu[i].score);
25 printf("output information :\n");
26 printf("学号,姓名,成绩:\n");
27
28 printf("用下标法输出数组元素\n");
29 for(i=0;i<N;i++)
30 printf("%d\t%s\t%4.1f\n",stu[i].num,stu[i].name,stu[i].score);
31
32 printf("\n用指针法输出数组元素\n");
33 for(;p<(stu+N);p++)
34 printf("%d\t%s\t%4.lf\n",p->num,p->name,p->score);
35 }
36 //-------------------------------2
37 #include<stdio.h>
38 #define N 5
39 struct student
40 {
41 int num;
42 char name[20];
43 float score;
44 };
45 void output(struct student s[N])
46 {
47 int i,j;
48 for(i=0;i<N;i++)
49 printf("num=%d,name=%s,score=%f",s[i].num,s[i].name,s[i].score);
50 printf("\n");
51 }
52 void main()
53 {
54 struct student stu[N];
55 int i,j;
56 printf("input information:\n");
57 printf("学号,姓名,三门课的成绩:\n");
58 for(i=0;i<N;i++)
59 scanf("%d%s%f",&stu[i].num,stu[i].name,&stu[i].score);
60 printf("output information:\n");
61 output(stu);
62 }
63 //---------------------------------3
64 #include<stdio.h>
65 struct student
66 {
67 int num;
68 char name[20];
69 float score;
70 };
71 struct student input()
72 {
73 struct student stu;
74 printf("input information:\n");
75 printf("学号\t姓名\t成绩:\n");
76 scanf("%d%s%f",&stu.num,stu.name,&stu.score);
77 return(stu);
78 };
79 void output(struct student s)
80 {
81 printf("output information:\n");
82 printf("学号\t姓名\t成绩:\n");
83 printf("%d%t%s%t%f\n",s.num,s.name,s.score);
84 }
85 void main()
86 {
87 struct student s1;
88 s1=input();
89 output(s1);
90 }
91 //---------------------------------------4
92 #include<stdio.h>
93 #include<stdlib.h>
94 #include<string.h>
95 typedef struct student
96 {
97 int num;
98 char name[10];
99 }STU;//自定义新类型STU
100 void main()
101 {
102 STU*p;//定义结构体类型指针p
103 p=(STU*)malloc(sizeof(STU));//从内存分配STU型大小的空间,并让p指向空着的首地址
104 p->num=1005;//对p所指向的空间进行内容赋值,包括学号和姓名
105 strcpy(p->name,"LiuHui");
106 printf("num=%d,name=%s\n",p->num,p->name);
107 free(p);//释放p所指向的内存空间
108 }
1 #include <stdio.h>
2
3 int main(void)
4 {
5 char ch;
6 do
7 {
8
9 int a,b,c;
10
11
12 printf ("请输入 加数a = %c\n");
13 scanf ("%d",&a);
14
15 printf ("请输入 加数b = %c\n");
16 scanf ("%d",&b);
17
18 c = a+b;
19 printf ("你输入的两数之和为:%d\n",c);
20 printf ("继续请输入Y\n");
21 scanf (" %c", &ch);
22 }while ('y'==ch||'Y'==ch);
23
24
25 return 0;
26 }