Write a program to accept records of different states using array of structures. The structure should contain char state, int population, int literacy rate and int per capita income. Assume suitable data. Display the state whose literacy rate is highest and whose per capita income is highest.
CODING:#include <stdio.h>
#include<conio.h>
void main()
{
struct state{
char name[30];
int pop,literacy,income;
}state[5],temp;
int a,b;
clrscr();
printf("\nState\n-----");
for(a=0;a<5;a++)
{
printf("\nName : ");
flushall(); gets(state[a].name);
printf("Population : ");
flushall(); scanf("%d",&state[a].pop);
printf("Literacy Rate (out of 100%) : ");
flushall(); scanf("%d",&state[a].literacy);
printf("Per Capita Income : Rs.");
flushall(); scanf("%d",&state[a].income);
}
for(a=0;a<5;a++)
for(b=a+1;b<3;b++)
if(state[a].literacy<state[b].literacy)
{
temp=state[a];
state[a]=state[b];
state[b]=temp;
}
printf("\nState with highest literacy rate : %s",state[0].name);
for(a=0;a<3;a++)
for(b=a+1;b<3;b++)
if(state[a].income<state[b].income)
{
temp=state[b];
state[a]=state[b];
state[b]=temp;
}
printf("\n\nState with highest per capita income : %s",temp.name);
getch();
}
Comments
Post a Comment