Dynamic Memory allocation Learning Note 2

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.