Advertisement
informaticage

Stuct students test

Oct 6th, 2017
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     typedef struct Student
  7.     {
  8.       char name[100];
  9.       char birth_date[12];
  10.       float scores[10];
  11.     } Student;
  12.  
  13.     int student_number;
  14.     printf("Number of students: ");
  15.     scanf("%d", &student_number);
  16.  
  17.     Student *students = malloc(sizeof(Student) * student_number);
  18.     int i;
  19.     for(i = 0; i < student_number; i++) {
  20.         printf("Student number %d", i);
  21.         printf("Name, Birth date %d", i);
  22.         scanf("%s %s", &students[i].name, &students[i].birth_date);
  23.         printf("Number of exams for the student %s", students[i].name);
  24.         int exam_number;
  25.         scanf("%d", &exam_number);
  26.         int j;
  27.         memset(students[i].scores, 0, 10 * sizeof(float));
  28.         for(j = 0; j < exam_number; j++) {
  29.             printf("Exam number %d", j);
  30.             scanf("%f", &students[i].scores[j]);
  31.         }
  32.     }
  33.  
  34.     printf("Printing student average: \n");
  35.     for(i = 0; i < student_number; i++) {
  36.         printf("Student number %d - Name: %s - date of bird: %s ", i, students[i].name, students[i].birth_date);
  37.         float sum = 0;
  38.         int j;
  39.         for(j = 0; j < 10; j++) {
  40.             sum += students[i].scores[j];
  41.         }
  42.         printf("Student scoresum : %f", sum);
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement