Completely Solved C, C++ Programs Assignment.

 Quick Search Database Videos Tutorials Ebooks Forums FAQ Aboutus Household Industrial Manufacturing Service Shopping Transportation

### C Program a structure which stores information about hotels which stores information about name, grade, room change, no of rooms. a) Print the hotels of given grade in order of roomchange. b) Print the hotels with roomchange less than a given change.

 Filed Under: Sample C program

Problem 71. C Program a structure which stores information about hotels which stores information about name, grade, room change, no of rooms. a) Print the hotels of given grade in order of roomchange. b) Print the hotels with roomchange less than a given change.
#include<stdio.h>
#include<conio.h>
main( )
{
struct hotel
{
char name[20];
char city[10];
int rc,nr;
};
struct hotel ht[20],t;
int i,n,j,c;
char gr;
clrscr( );
printf(“enter no. of hotelsn”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter name of hotel n”);
scanf(“%s”,&ht[i].name);
printf(“enter name of city n”);
scanf(“%s”,&ht[i].city);
printf(“enter the grade n”);
printf(“enter room charge n”);
scanf(“%d”,&ht[i].rc);
printf(“enter no of rooms n”);
scanf(“%d”,&ht[i].nr);
}
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
{
t=ht[j];
ht[j]=ht[j+i];
ht[j+1]=t;
}
printf(“enter a grade to print the hotels n”);
gr=getche();
clrscr();
printf(“hotel name city grade roomcharge no of room”);
for(i=0;i<n;i++)
printf(“%s %s %c %d %d”,ht[i].name,ht[i].city,ht[i].grade,ht[i].r c,ht[i].nr);
getch();
printf(“enter a room charge to print hotels less than given charge n”);
scanf(“%d”,&c);
printf(“hotel name city grade roomcharge no of rooms”);
for(i=0;i<n;i++)
if(c<=ht[i].rc)
printf(“%s %s %c %d %d”,ht[i].name,ht[i].city,h[i].grade,ht[i].rc ,ht[i].nr);
}

C compiler: gcc 4.1.2

Back to main directory: Sample C Program | Software Practical | Solved C Assignment