Write a c program to search an element in an array using
recursion



Write a c program to search an element in an array using recursion ..

Answer / lel

#include<stdio.h>
#include<conio.h>
void search(int a[], int k, int n, int j);
int main()
{
int a[12],i,k,j=0,n;
printf("Enter the no. of ele : \n");
scanf("%d",&n);
printf("Enter the ele\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the ele you want to search : \n");
scanf("%d",&k);
search(a,k,n,j);
getch();
return 0;
}
void search(int a[], int k, int n, int j)
{
if(j<n)
{
if(k==a[j])
{
printf("The ele is present. It is %d at a[%d]",a[j],j);
}
else
{
search(a,k,n,j+1);
}
}
else
printf("The ele you are searching for is not present !!");
}

Is This Answer Correct ?    7 Yes 2 No

Post New Answer

More C Code Interview Questions

how to check whether a linked list is circular.

11 Answers   Microsoft,


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

1 Answers  


Is the following code legal? typedef struct a { int x; aType *b; }aType

1 Answers  


Is it possible to print a name without using commas, double quotes,semi-colons?

7 Answers  


abcdedcba abc cba ab ba a a

2 Answers  






void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

2 Answers  


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

0 Answers   IBM,


write a c program to Reverse a given string using string function and also without string function

1 Answers  


given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

8 Answers  


Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique.

5 Answers   IITR, Microsoft, Nike,


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


Who could write how to find a prime number in dynamic array?

1 Answers  


Categories