Niloy007

Structure

Nov 15th, 2020
618
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[40];
  5.     int id;
  6.     double marks;
  7. };
  8.  
  9.  
  10.  
  11. int main() {
  12.     int size;
  13.     printf("Enter student's number:\n");
  14.     scanf("%d", &size);
  15.  
  16.     struct Student students[size];
  17.  
  18.     // Input
  19.     for (int i = 0; i < size; i++) {
  20.         printf("Enter %d no student's name:\n", i + 1);
  21.         fflush(stdin);
  22.         gets(students[i].name);
  23.         fflush(stdout);
  24.         printf("Enter student's ID:\n");
  25.         scanf("%d", &students[i].id);
  26.         printf("Enter student's marks:\n");
  27.         scanf("%lf", &students[i].marks);
  28.     }
  29.  
  30.     // Output
  31.     printf("\nOutput:\n");
  32.     for (int i = 0; i < size; i++) {
  33.         printf("Name: %s\n", students[i].name);
  34.         printf("ID: %d\n", students[i].id);
  35.         printf("Marks: %lf\n\n", students[i].marks);
  36.     }
  37.     printf("\n");
  38.  
  39.  
  40.     double maxNum = -1;
  41.     int index = -1;
  42.  
  43.     for (int i = 0; i < size; i++) {
  44.         if(students[i].marks > maxNum) {
  45.             maxNum = students[i].marks;
  46.             index = i;
  47.         }
  48.     }
  49.     printf("\nMax number student: %s\n", students[index].name);
  50.     printf("Maxmimum marks is: %lf\n", students[index].marks);
  51.     printf("ID: %d\n", students[index].id);
  52. }
  53.  
  54. // int main() {
  55. //  struct Student studentOne;
  56. //  printf("Enter student's name:\n");
  57. //  gets(studentOne.name);
  58. //  printf("Enter student's ID:\n");
  59. //  scanf("%d", &studentOne.id);
  60. //  printf("Enter student's marks:\n");
  61. //  scanf("%lf", &studentOne.marks);
  62.  
  63. //  printf("\nOutput:\n");
  64. //  printf("Name: %s\n", studentOne.name);
  65. //  printf("ID: %d\n", studentOne.id);
  66. //  printf("Marks: %lf\n", studentOne.marks);
  67. // }
  68.  
  69. /*
  70.  
  71.     Structure
  72.         -> Create a structure
  73.         -> declare it
  74.         -> Input
  75.         -> Output
  76.     Array of Structure
  77.         -> Create a structure
  78.         -> declare it
  79.         -> Input
  80.         -> Output
  81.         -> Find Maximum mark
  82.         -> Find Maximum student's name
  83.  
  84. */
RAW Paste Data