DFS :: Searching

#include<stdio.h>
void main()
{
int *iptr,size,key,flag=-1;
ankur:
printf(“Enter the size of the array”);
scanf(“%d”,&size);
if(size<1)
{
printf(“Invalid Size\nTry Again!!!!!\n”);
goto ankur;
}
else
{
iptr=new int[size];
for(int i=0;i<size;i++)
{
printf(“Enter element%d:”,i+1);
scanf(“%d”,&iptr[i]);
}
printf(“Enter element to be searched:”);
scanf(“%d”,&key);
for(i=0;i<size;i++)
{
if(iptr[i]==key)
{
flag=i;
printf(“%d is found at %d position in the array”,key,flag+1);
break;
}
}
if(flag==-1)
printf(“%d is not found in the array”,key);
}
}

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.