Write a program to define structure with tag state with fields state name, number of districts and total population.Read and display the data.
CODING:
#include <stdio.h>
void main()
{
struct state{
char name[30];
int district;
int popln;
}state={"",0,0};
clrscr();
printf("\nEnter state name : ");
flushall();
gets(state.name);
printf("Enter no. of districts : ");
flushall();
scanf("%d",&state.district);
printf("Enter population : ");
flushall();
scanf("%d",&state.popln);
clrscr();
printf("STATE\n-----\nName\t\t : %s\nDistricts"
"\t : %d\nPopulation\t : %d",state.name,state.district,state.popln);
getch();
}
CODING:
#include <stdio.h>
void main()
{
struct state{
char name[30];
int district;
int popln;
}state={"",0,0};
clrscr();
printf("\nEnter state name : ");
flushall();
gets(state.name);
printf("Enter no. of districts : ");
flushall();
scanf("%d",&state.district);
printf("Enter population : ");
flushall();
scanf("%d",&state.popln);
clrscr();
printf("STATE\n-----\nName\t\t : %s\nDistricts"
"\t : %d\nPopulation\t : %d",state.name,state.district,state.popln);
getch();
}
Comments
Post a Comment