Niloy007

Today's Class Code (July 12, 2020)

Jul 12th, 2020
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. // struct book {
  4. //  char name[40];
  5. //  int publishYear;
  6. // };
  7.  
  8. // int main() {
  9. //  // datatype variable name;
  10. //  struct book BookOne;
  11. //  printf("Enter a book name:\n");
  12. //  fgets(BookOne.name, 40, stdin);
  13. //  printf("Enter The book's publish year\n");
  14. //  scanf("%d", &BookOne.publishYear);
  15. //  printf("The book name is %s", BookOne.name);
  16. //  printf("Publish Year: %d\n", BookOne.publishYear);
  17. // }
  18.  
  19.  
  20.  
  21.  
  22. // structure of array
  23.  
  24. struct student {
  25.     char studentName[40];
  26.     int id;
  27.     double marks;
  28. };
  29.  
  30.  
  31. int main() {
  32.     int totalStudent;
  33.     printf("Enter the number of total student\n");
  34.     scanf("%d", &totalStudent);
  35.  
  36.     struct student Student[totalStudent];
  37.     int i;
  38.  
  39.     // for taking input from the user
  40.     for (i = 0; i < totalStudent; i++) {
  41.         printf("Student information no: %d\n", i + 1);
  42.         printf("Enter student name:\n");
  43.         fflush(stdin);
  44.         fgets(Student[i].studentName, 40, stdin);
  45.         fflush(stdout);
  46.         printf("Enter student id:\n");
  47.         scanf("%d", &Student[i].id);
  48.         printf("Enter student marks:\n");
  49.         scanf("%lf", &Student[i].marks);
  50.         printf("\n");
  51.     }
  52.  
  53.     // Print the information
  54.     for (i = 0; i < totalStudent; i++) {
  55.         printf("Name: %s", Student[i].studentName);
  56.         printf("ID: %d\n", Student[i].id);
  57.         printf("Marks: %.2lf\n", Student[i].marks);
  58.         printf("\n");
  59.     }
  60.  
  61.     // Find the maximum number of a student
  62.     double max = 0;
  63.     for (i = 0; i < totalStudent; i++) {
  64.         if(Student[i].marks > max) {
  65.             max = Student[i].marks;
  66.         }
  67.     }
  68.  
  69.     printf("The maximum number of a student is %lf\n", max);
  70.  
  71.     // print the information who has the maximum marks
  72.     int index = 0;
  73.     max = 0;
  74.     for (i = 0; i < totalStudent; i++) {
  75.         if(Student[i].marks > max) {
  76.             max = Student[i].marks;
  77.             index = i;
  78.         }
  79.     }
  80.  
  81.    
  82.     printf("Name: %s", Student[index].studentName);
  83.     printf("ID: %d\n", Student[index].id);
  84.     printf("Marks: %.2lf\n", Student[index].marks);
  85. }
RAW Paste Data