Sunday, 24 April 2022

6. Write a program to accept records of different states using array of structures. The structure should contain char state and number of int engineering colleges, int medical colleges, int management colleges and int universities. Calculate total colleges and display the state, which is having highest number of colleges.

 


#include<stdio.h>
#include<conio.h>

struct states
{
    char state[20];
    int engc, medc, manc, uni;
}s[20];

void main()
{
    int no,i,total[20],temp,k,max;
    clrscr();

    printf("how many state you want to enter: ");
    scanf("%d",&no);

    if(no>20)
    {
        printf("\n\n!! please enter less than 20");
    }
    else
    {
        for(i=0; i<no; i++)
        {
            printf("\nenter %d state : ",i+1);
            scanf("%s",s[i].state);
            printf("\nin %s state how many engineering college: ",s[i].state);
            scanf("%d",&s[i].engc);
            printf("in %s state how many medical college: ",s[i].state);
            scanf("%d",&s[i].medc);
            printf("in %s state how many management college: ",s[i].state);
            scanf("%d",&s[i].manc);
            printf("in %s state how mnay universities: ",s[i].state);
            scanf("%d",&s[i].uni);
            total[i] = s[i].engc + s[i].medc + s[i].manc + s[i].uni;
            printf("\n");
        }

        printf("\n\n!! total colleges !!\n");
        for(i=0; i<no; i++)
        {
            printf("\nin %s : %d",s[i].state,total[i]);

            printf("\n");
        }

        max= total[0];
        for(i=0; i<no; i++)
        {
                if(total[i] > max)
                {
                    max =  total[i];
                    k = i;
                }
                else if(max == total[0])
                {
                    k = 0;
                }
        }
            printf("\n-> in %s state highest number of %d colleges <-",
                    s[k].state,max);
    }
    getch();
}

/*  output:

enter how many state you want to enter: 3

enter 2 state : gujrat

in gujrat state how many engineering college: 13
in gujrat state how many medical college: 12
in gujrat state how many management college: 13
in gujrat state how mnay universities: 14

enter 2 state : rajasthan

in rajasthan state how many engineering college: 2
in rajasthan state how many medical college: 4
in rajasthan state how many management college: 7
in rajasthan state how mnay universities: 8


enter 3 state : up

in up state how many engineering college: 23
in up state how many medical college: 4
in up state how many management college: 10
in up state how mnay universities: 1



!! total colleges !!

in gujrat : 52

in rajasthan : 21

in up : 38

-> in gujrat state highest number of 52 colleges <-

*/

No comments:

Post a Comment

python programs

1. sum of two number