ACP2_8

#include <stdio.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(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.