#include <stdio.h> #include <stdlib.h>void main () {Struct stu_type{char num[15];char name[10];int age;int c;int math;int en;int sum;float ave;} *p,*p1;int n,i;printf ("Please enter the number of students:"); scanf ("%d", &n) ;p = (struct stu_type *) malloc ( sizeof (Struct stu_type) *n);p 1=p;for (i=0;i<n;i++) {printf ("Please enter the information for%d students \ n", i+1);p rintf ("Please enter the student number:"); scanf (" %s ", P1->num) ;p rintf (" Enter Name: "), scanf ("%s ", P1->name) ;p rintf (" Please enter Age: "); scanf ("%d ",&p1-> Age);p rintf ("Please enter C language score:"); scanf ("%d", &p1->c);p rintf ("Enter Math score:") scanf ("%d", &p1->math) ; printf ("Please input English score:"); scanf ("%d", &p1->en);p 1->sum = p1->c + p1->math + p1->en;p1->ave = (float) p1->sum/3;p1++; printf ("\ n");} printf (student number \ t name \ t age \TC language \ t math T-English \ t total score \ t average score \ n "); for (i=0;i<n;i++) {p->sum = p->c + p-> math + p-> en;p->ave = (float) p->sum/3;printf ("%-16s%s\t%d\t%d\t%d\t%d\t%d\t%5.1f\n", P->num,p->name,p->age,p->c, P->math,p->en,p->sum,p->ave) ;p + +;}}
Dynamic Memory allocation Learning Note 2