100% linear search with array pre-defined
#include <stdio.h>
void main()
{
int p,key,count=0;
int numbered_packets[5]={9,-1,7,4,5};
/*let there be some packets to be sent by Indian postal department which are numbered with some codes.After receiving them, we wish to search for a particular numbered packet becoz all packets might have got jumbled up */
printf("\n enter the key code to be searched:");
scanf("%d",&key);
for(p=0;p<5;p++)
{
if(numbered_packets[p]==key)
{
printf("\n packet with desired key found");
exit(0);
}
count=count+1;
}
if(count==5)
printf("\n packet with desired key not found");
}
void main()
{
int p,key,count=0;
int numbered_packets[5]={9,-1,7,4,5};
/*let there be some packets to be sent by Indian postal department which are numbered with some codes.After receiving them, we wish to search for a particular numbered packet becoz all packets might have got jumbled up */
printf("\n enter the key code to be searched:");
scanf("%d",&key);
for(p=0;p<5;p++)
{
if(numbered_packets[p]==key)
{
printf("\n packet with desired key found");
exit(0);
}
count=count+1;
}
if(count==5)
printf("\n packet with desired key not found");
}
ఔట్పుట్ తెరమీద
enter the key code to be searched:4packet with desired key found
మరోసారి Run చేస్తే ఔట్పుట్ తెరమీద
enter the key code to be searched:11
packet with desired key not found
packet with desired key not found
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.