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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2228


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2032


What is full form of PEPSI

1875


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3861


Write a routine to implement the polymarker function

4390






Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2867


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2342


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2267


How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.

1938


How can you relate the function with the structure? Explain with an appropriate example.

2925


Sir... please give some important coding questions asked by product companies..

1805


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

3036


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1082


Design an implement of the inputs functions for event mode

2970


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3722