Google Ads

Wednesday, May 27, 2009

Searching Sorting


SEARCHING AND SORTING OF BOOK- PROGRAM


#include”stdio.h”

#include “conio.h”

void main()

{

struct book

{

char tit[30],aut[30];

}b[10],temp;

int i,j,ch,n,con,x,c,p;

char str[30];

clrscr();

printf("\nEnter the Total no.of books :");

scanf("%d",&n);

for(i=0;i

{

printf("\nEnter the Title of the book :");

scanf("%s",&b[i].tit);

printf("Enter the Author name :");

scanf("%s",&b[i].aut);

}

p1: printf("\n1.Author Search\n2.Book Search\n3.Sort");

printf("\nEnter your choice :");

scanf("%d",&ch);

switch(ch)

{

case 1:

c=0;

printf("\nEnter the Author name to be searched :");

scanf("%s",str);

for(j=0;j

{

x=strcmp(b[j].aut,str);

if(x==0)

{

c=1;

p=j;

}

}

if(c==0)

printf("\nAuthor Name Not Found");

else

{

printf("\n\t\t\tSearched Result");

printf("\n\t\t\t---------------");

printf("\nTitle of the book : %s\nAuthor Name : %s\n",b[p].tit,b[p].aut);

}

break;

case 2:

c=0;

printf("\nEnter the Book name to be searched :");

scanf("%s",str);

for(j=0;j

{

x=strcmp(b[j].tit,str);

if(x==0)

{

c=1;

p=j;

}

}

if(c==0)

printf("\nBook Not Found");

else

{

printf("\n\t\t\tSearched Result");

printf("\n\t\t\t---------------");

printf("\nTitle of the book : %s\nAuthor Name : %s\n",b[p].tit,b[p].aut);

}

break;

case 3:

for(i=0;i

{

for(j=i+1;j

{

if(strcmp(b[i].tit,b[j].tit)>0)

{

strcpy(temp.tit,b[i].tit);

strcpy(temp.aut,b[i].aut);

strcpy(b[i].tit,b[j].tit);

strcpy(b[i].aut,b[j].aut);

strcpy(b[j].tit,temp.tit);

strcpy(b[j].aut,temp.aut);

}

}

}

printf("\nTitle of the Book");

printf("\n-----------------");

for(i=0;i

printf("\n%s",b[i].tit);

break;

default:

printf("\nEnter between 1 to 3");

break;

}

printf("\n Do you want to continue press 1 : ");

scanf("%d",&con);

if(con==1)

goto p1;

getch();

}

No comments:

Post a Comment