fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct std
  5. {
  6. char name[30];
  7. char id[15];
  8. float cgpa;
  9. };
  10.  
  11. int main()
  12. {
  13. struct std *p;
  14. int n, i, max = 0;
  15.  
  16. printf("Students of CSE-207, Summer 2020\n");
  17. printf("Enter number of students: ");
  18. scanf("%d", &n);
  19.  
  20. p = (struct std *)malloc(n * sizeof(struct std));
  21.  
  22. if (p == NULL)
  23. {
  24. printf("Memory not allocated\n");
  25. return 0;
  26. }
  27.  
  28. for (i = 0; i < n; i++)
  29. {
  30. printf("\nStudent %d\n", i + 1);
  31. printf("Enter name: ");
  32. scanf(" %[^\n]", p[i].name);
  33. printf("Enter id: ");
  34. scanf("%s", p[i].id);
  35. printf("Enter cgpa: ");
  36. scanf("%f", &p[i].cgpa);
  37. }
  38.  
  39. for (i = 1; i < n; i++)
  40. {
  41. if (p[i].cgpa > p[max].cgpa)
  42. max = i;
  43. }
  44.  
  45. printf("\nStudent who obtained highest CGPA: %s\n", p[max].name);
  46. printf("CGPA: %.2f\n", p[max].cgpa);
  47.  
  48. free(p);
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Students of CSE-207, Summer 2020
Enter number of students: 
Student who obtained highest CGPA: 
CGPA: 0.00