Niloy007

Sumaiya's Problem

Jun 1st, 2020
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. struct Student {
  4.     char name[20];
  5.     int id;
  6.     double marks;
  7. };
  8.  
  9. typedef struct Student student;
  10.  
  11. int main() {
  12.     student sOne[5];
  13.     for (int i = 0; i < 5; i++) {
  14.         printf("Information of %d no student\n", i + 1);
  15.         printf("Enter student's name\n");
  16.         fflush(stdin);
  17.         scanf("%s", &sOne[i].name);
  18.         fflush(stdout);
  19.         printf("Enter student's id\n");
  20.         scanf("%d", &sOne[i].id);
  21.         printf("Enter student's marks\n");
  22.         scanf("%lf", &sOne[i].marks);
  23.     }
  24.  
  25.     for (int i = 0; i < 5; i++) {
  26.         printf("Student %d:\n", i + 1);
  27.         printf("Name: %s\n", sOne[i].name);
  28.         printf("ID: %d\n", sOne[i].id);
  29.         printf("Exam Marks: ");
  30.         printf("%.2lf ", sOne[i].marks);
  31.         printf("\n");
  32.     }
  33.  
  34.     printf("Marks of the students are given below\n");
  35.  
  36.     // Maximum part
  37.     double max = sOne[0].marks;
  38.     int index = 0;
  39.     for (int i = 1; i < 5; i++) {
  40.         if (max < sOne[i].marks) {
  41.             max = sOne[i].marks;
  42.             index = i;
  43.         }
  44.     }
  45.     printf("Maximum marks holder student: %s %.2lf\n", sOne[index].name, sOne[index].marks);
  46.  
  47.     // Minimum Part
  48.     double min = sOne[0].marks;
  49.     index = 0;
  50.     for (int i = 1; i < 5; i++) {
  51.         if (min > sOne[i].marks) {
  52.             min = sOne[i].marks;
  53.             index = i;
  54.         }
  55.     }
  56.     printf("Minimum marks holder student: %s %.2lf\n", sOne[index].name, sOne[index].marks);
  57.  
  58.     // Average part
  59.  
  60.     double sum = 0;
  61.     for (int i = 0; i < 5; i++) {
  62.         sum += sOne[i].marks;
  63.     }
  64.     double avg = sum / 5;
  65.  
  66.     printf("Average marks: %.2lf\n", avg);
  67. }
RAW Paste Data