Solution:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct book
{
int bno,bcost,baccno;
char bname[20],bpub[20],bauthor[20];
}p[10];
int main()
{
int n,i,ch,largest ;
char pubname[20],authorname[20];
printf("/*How Many Records of Books You Want to Add*/\n\nEnter Limit : ");
scanf("%d",&n);
printf("------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("\tEnter Details of Book-%d",i+1);
printf("\n------------------------------------------\n");
printf("Book Number : ");
scanf("%d",&p[i].bno);
printf("Book Name : ");
scanf("%s",p[i].bname);
printf("Author Name : ");
scanf("%s",p[i].bauthor);
printf("Publication : ");
scanf("%s",p[i].bpub);
printf("Cost : ");
scanf("%d",&p[i].bcost);
printf("Accession Number : ");
scanf("%d",&p[i].baccno);
printf("------------------------------------------\n");
}
while(1)
{
printf("\n\t\tMENU\n");
printf("------------------------------------------\n");
printf("\n1.All Books Costing Above Rs. 500");
printf("\n2. Books having maximum price");
printf("\n3.Exit");
printf("\n------------------------------------------\n");
printf("\nEnter Your Choice : ");
scanf("%d",&ch);
printf("\n");
switch(ch)
{
case 1:
for(i=0;i<n;i++)
{
if(p[i].bcost>500)
{
printf("Book Number : %d\n",p[i].bno);
printf("Book Name : %s \n",p[i].bname);
printf("Cost : %d\n",p[i].bcost);
printf("Accession Number : %d\n",p[i].baccno);
printf("\n------------------------------------------\n");
}
}
break;
case 2:
for(i=0;i<n;i++)
{ largest = p[0].bcost;
if (largest < p[i].bcost){
largest = p[i].bcost;
}
}
printf("Cost : %d\n",largest);
for(i=0;i<n;i++)
{
if(p[i].bcost==largest)
{
printf("Book Number : %d\n",p[i].bno);
printf("Book Name : %s \n",p[i].bname);
printf("Cost : %d\n",p[i].bcost);
printf("Accession Number : %d\n",p[i].baccno);
printf("\n------------------------------------------\n");
}
}
break;
case 3:
exit(0);
}
}
return 0;
}
0 Comments