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");
}

ఔట్పుట్ తెరమీద
enter the key code to be searched:4
packet with desired key found 

మరోసారి Run చేస్తే  ఔట్పుట్ తెరమీద
enter the key code to be searched:11
packet with desired key not found

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

Assignment to gain eligibility to industry visit

வணக்கம் Participants can do one or more of these Assignments

Seniors assignment _ must for registration to attend workshop by TCS యశ్వంత్ జీ