P191. Program to store 5 student database which contains 3 information ( roll no – name – marks ) in unsorted order, ask the user for input in which way he/she needs the data. 1 – Display name of highest marks student. 2 – Even roll number information’s. 3 – Name ending with a vowel – display its information.

 #include<stdio.h>

#include<string.h>

void print(void);

struct stu

{

    int roll;

    char name[10];

    float t_marks;

};

 

void main()

{

 

    struct stu v[5];

    int i,j,ele,choice,high,len;

    ele=sizeof(v)/sizeof(v[0]);

 

    for(i=0;i<ele;i++)

    {

    printf("Enter roll number : ");

    scanf("%d",&v[i].roll);

    printf("Enter name : ");

    scanf(" %s",v[i].name);

    printf("Enter total marks : ");

    scanf("%f",&v[i].t_marks);

    printf("\n");

    }

    printf("\n");

 

    while(1)

    {

    printf(" 1 - Display name of highest total marks student\n 2 - Display even roll numbers information\n 3 - Name ending with a vowel\n ");

 

    printf("Enter choice : ");

    scanf("%d",&choice);

    printf("\n");

 

    switch(choice)

    {

        case 1 :

        high=v[0].t_marks;

        for(i=1;i<ele;i++)

        {

            if(high<v[i].t_marks)

                high=v[i].t_marks;

        }

        for(i=0;i<ele;i++)

        {

            if(high==v[i].t_marks)

            {

                printf("Highest marks : %s",v[i].name);

                break;

            }

        }

        break;

 

        case 2 :

        for(i=0;i<ele;i++)

        {

            if((v[i].roll%2)==0)

            {

                printf("%d %s %f \n",v[i].roll,v[i].name,v[i].t_marks);

            }

        }

        printf("\n");

        break;

 

        case 3 :

        for(i=0;i<ele;i++)

        {

            for(len=0;v[i].name[len];len++);

            if(v[i].name[len-1]=='a' || v[i].name[len-1]=='e'|| v[i].name[len-1]=='i'|| v[i].name[len-1]=='o'|| v[i].name[len-1]=='u')

            {

                printf("%d %s %f \n",v[i].roll,v[i].name,v[i].t_marks);

            }

        }

        printf("\n");

        break;

 

    }

    }

}

Comments