#include <stdio.h>
#include <stdlib.h>

struct std
{
    char name[30];
    char id[15];
    float cgpa;
};

int main()
{
    struct std *p;
    int n, i, max = 0;

    printf("Students of CSE-207, Summer 2020\n");
    printf("Enter number of students: ");
    scanf("%d", &n);

    p = (struct std *)malloc(n * sizeof(struct std));

    if (p == NULL)
    {
        printf("Memory not allocated\n");
        return 0;
    }

    for (i = 0; i < n; i++)
    {
        printf("\nStudent %d\n", i + 1);
        printf("Enter name: ");
        scanf(" %[^\n]", p[i].name);
        printf("Enter id: ");
        scanf("%s", p[i].id);
        printf("Enter cgpa: ");
        scanf("%f", &p[i].cgpa);
    }

    for (i = 1; i < n; i++)
    {
        if (p[i].cgpa > p[max].cgpa)
            max = i;
    }

    printf("\nStudent who obtained highest CGPA: %s\n", p[max].name);
    printf("CGPA: %.2f\n", p[max].cgpa);

    free(p);
    return 0;
}
