Unit Pr1
Unit Pr1
number of districts and total population. Read and display the data.
# include <stdio.h>
# include <conio.h>
struct state
char *name;
int dist;
long pop;
};
void main()
clrscr();
state s;
printf ("\n Enter state name, number of dist. and population : ");
getch();
}
2-Write a program to create a list of books details. The details of a book
include title, author, publisher, publishing year, number of pages, and price.
#include<stdio.h>
#include<conio.h>
#define size 10
struct bk
char *ti[20];
char *pub[20];
int py;
int page;
int pr;
};
void main()
struct bk b[size];
int i=0,n;
clrscr();
scanf("%d",&n);
scanf("%s",&b[i].ti);
printf("Enter Name of Author : \n");
scanf("%s",&b[i].author);
scanf("%s",&b[i].pub);
scanf("%d",&b[i].py);
scanf("%d",&b[i].page);
scanf("%d",&b[i].pr);
printf("%s\t",b[i].ti);
printf("%s\t",b[i].author);
printf("%s\t",b[i].pub);
printf("%d\t",b[i].py);
printf("%d\t",b[i].pr);
getch();
}
3. Define a structure called Item with members: Item_code, Item_name,
Price. Create an array of five Items. Create a function which accepts the Item
array and modifies each element with an increase of 10% in the price.
#include<stdio.h>
#include<conio.h>
struct date
int date,month,year;
};
int i;
if(d[i].month == 1)
printf("January");
else if(d[i].month == 2)
printf("February");
else if(d[i].month == 3)
{
printf("March");
else if(d[i].month == 4)
printf("April");
else if(d[i].month == 5)
printf("May");
else if(d[i].month == 6)
printf("June");
else if(d[i].month == 7)
printf("July");
else if(d[i].month == 8)
printf("August");
else if(d[i].month == 9)
printf("Sepember");
}
printf("October");
printf("November");
printf("December");
else
printf("Unvalide Month");
void main()
int i;
clrscr();
for(i=0;i<2; i++)
scanf ("%d",&d[i].date);
scanf ("%d",&d[i].month);
scanf("%d",&d[i].year);
printf("%d \ %d \ %d.",d[i].date,d[i].month,d[i].year);
// month_name(d);
getch();
}
4. Define a structure to represent a date. Use your structures that accept two
different dates in the format mm dd of the same year. Write a C program to
display the month names of both dates.
#include<stdio.h>
#include<conio.h>
struct date
int date,month,year;
};
int i;
if(d[i].month == 1)
printf("January");
else if(d[i].month == 2)
printf("February");
else if(d[i].month == 3)
{
printf("March");
else if(d[i].month == 4)
printf("April");
else if(d[i].month == 5)
printf("May");
else if(d[i].month == 6)
printf("June");
else if(d[i].month == 7)
printf("July");
else if(d[i].month == 8)
printf("August");
else if(d[i].month == 9)
printf("Sepember");
}
printf("October");
printf("November");
printf("December");
else
printf("Unvalide Month");
void main()
int i;
clrscr();
for(i=0;i<2; i++)
scanf ("%d",&d[i].date);
scanf ("%d",&d[i].month);
scanf("%d",&d[i].year);
printf("%d \ %d \ %d.",d[i].date,d[i].month,d[i].year);
month_name(d);
getch();
}
5-Define a structure that can describe a Hotel. It should have members that
include name, address, grade, room charges, grade and no of rooms. Write a
function to print out all hotel details with room charges less than a given
value
#include<stdio.h>
#include<conio.h>
struct h
char name[30];
char add[20];
int gra;
int chr;
int room;
};
void hotel();
struct h s[]={
};
void main()
{
clrscr();
int i;
char c;
for(i=0;i<=3;++i)
printf("\nHOTEL NAME:%s",s[i].name);
printf("\nADDRESH:%s",s[i].add);
printf("\nGRADE:%d",s[i].gra);
printf("\nCHARGES:%d",s[i].chr);
printf("\nNO.OF ROOM:%d\n",s[i].room);
hotel();
getch();
void hotel()
int i,k;
char c;
scanf("%d",k);
for(i=0;i<=3;++i)
{
if(s[i].chr<=k)
printf("\nADDRESH:%s",s[i].add);
printf("\nGRADE:%d",s[i].gra);
printf("\nCHARGES:%d",s[i].chr);
printf("\nNO.OF ROOM:%d\n",s[i].room);
getch();
}
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 sta
char name[15];
int e,m,mng,uni,t;
};
void main()
int i,c;
clrscr();
for(i=0;i<=2;i++)
printf("\n%d)State Name:",i+1);
scanf("%s",s[i].name);
printf("Engneering College:");
scanf("%d",&s[i].e);
printf("Medical College:");
scanf("%d",&s[i].m);
printf("Management College:");
scanf("%d",&s[i].mng);
printf("Universities College:");
scanf("%d",&s[i].uni);
printf("-----------------------");
for(i=0;i<=2;i++)
s[i].t=s[i].e+s[i].m+s[i].mng;
else
getch();
}
7. Define a structure by name time with members seconds, minutes and
hours of int type. A variable of the structure would thus represent time. If
time1 and time2 are two variables of the structure type, write a program to
find the difference of two times using a function.
#include <stdio.h>
#include <conio.h>
struct TIME {
int seconds;
int minutes;
int hours;
};
int main()
getch();
return 0;
--start.minutes;
start.seconds += 60;
--start.hours;
start.minutes += 60;
}
diff->minutes = start.minutes - stop.minutes;
population, int literacy rate and int per capita income. Assume
suitable data. Display the state whose literacy rate is highest and
#include <stdio.h>
#include <conio.h>
struct state
char name[15];
int pop,lit,inc;
};
void main()
int i;
clrscr();
scanf("%s",&s[i].name);
printf("Population :");
scanf("%d",&s[i].pop);
scanf("%d",&s[i].lit);
scanf("%d",&s[i].inc);
printf("\n\n");
else
else
getch();
}
9. Define a structure employee with members employee name, basic pay,
dearness allowance, house rent, net salary. Declare an array of 5 employees.
Write a function which calculates the net salary of employees and prints all
employee details in descending order of their net salary.
#include <stdio.h>
#include <conio.h>
struct emp
char name[20];
int p,da,hr,ns;
};
void main()
int i,t=0;
clrscr();
scanf("%s",&e[i].name);
scanf("%d",&e[i].p);
scanf("%d",&e[i].hr);
scanf("%d",&e[i].ns);
printf("\n");
printf("\n");
void tl();
t = t + e[i].ns;
getch();
}
10. Define a structure with tag population with fields Men and Women.
Create structure with in structure using state and population structure. Read
and display the data.
#include <conio.h>
#include<stdio.h>
struct population
int nw;
int nm;
};
struct state
char name[10];
};
void main()
scanf("%s%d%d",s1.name,&s1.p1.nw,&s1.p1.nm);