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

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

3712


How to palindrom string in c language?

8845


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

1798


In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.

2384


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

3109






Write a routine to implement the polymarker function

4379


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 ?

2261


write a program for area of circumference of shapes

2030


why nlogn is the lower limit of any sort algorithm?

2374


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2139


write a simple calculator c program to perform addition, subtraction, mul and div.

3145


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

2021


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

3028


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

1069


Develop a routine to reflect an object about an arbitrarily selected plane

2996