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

Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }

1 Answers  


#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }

1 Answers  


main() { extern int i; i=20; printf("%d",sizeof(i)); }

2 Answers  


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,






what is the code of the output of print the 10 fibonacci number series

2 Answers  


In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }

1 Answers  


Cluster head selection in Wireless Sensor Network using C programming language.

0 Answers  


how to check whether a linked list is circular.

11 Answers   Microsoft,


Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }

29 Answers   IBM, TCS, UGC NET, Wipro,


#include<stdio.h> int main() { int x=2,y; y=++x*x++*++x; printf("%d",y); } Output for this program is 64. can you explain how this output is come??

1 Answers  


Categories