GU.Sturcture.1 Write a program to define structure with tag state with fields state name, number of districts and total population. Read and display the data.

//Program Prepared by Chirag Jadav, FYBCA-2018-19

Write a program to define structure with tag state with fields state name, number of districts and total population. Read and display the data.

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

struct state
{
char state[99];
int population , literacy , per_capita_income;
}s[5];

void main()
{
int i,n,maxlit,maxin,a,b; /* i is for loop, n is for no of state,
   maxlit is for maximum literacy and
   maxin is for maximum per_capta_income..!! */
clrscr();
printf("\nEnter no of state : ");
scanf("%d",&n);

printf("\n---- Enter details below ----\n");
for(i=0;i<n;i++)
{
printf("\nState : ");
scanf("%s",s[i].state);

printf("\nPopulation : ");
scanf("%d",&s[i].population);

printf("\nLiteracy : ");
scanf("%d",&s[i].literacy);

printf("\nPer capita income : ");
scanf("%d",&s[i].per_capita_income);
}

maxlit=s[0].literacy;
maxin=s[0].per_capita_income;

for(i=1;i<n;i++)
{
if(maxlit<s[i].literacy)
{
maxlit=s[i].literacy;
a=i;
}
if(maxin<s[i].per_capita_income)
{
maxin=s[i].per_capita_income;
b=i;
}
}

printf("%s state has highest literacy which is %d\n",s[a].state,maxlit);
printf("%s state has highest per capita income which is %d",s[b].state,maxin);
getch();
}

No comments:

Post a Comment