in Education by
Write C program that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Answer: Step 1: Start Step 2: Read n, a[i], key values as integers Step 3: Search the list While (a[i] != key && i <= n) i = i + 1 Repeat step 3 Step 4: Successful search if(i = n + 1) then print “Element not found in the list” Return(0) else print “Element found in the list” Return (i) Step 6: Stop Program: #include<stdio.h> #include void main() { int i, a[20], n, key, flag = 0; clrscr(); printf(“Enter the size of an array \n”); scanf(“%d”, &n); printf(“Enter the array elements”); for(i = 0; i < n; i++) { scanf(“%d”, &a[i]); } printf(“Enter the key elements”); scanf(“%d”, &key); for(i = 0; i < n; i++) { if(a[i] == key) { flag = 1; break; } } if(flag == 1) printf(“The key elements is found at location %d”, i + 1); else printf(“The key element is not found in the array”); getch(); } Input & Output: Enter the size of an array 6 Enter the array elements 50 10 5 200 20 1 Enter the key element 1 Explanation: please mark as BRAINLIST please

Related questions

0 votes
    Write a program to accept string from user and search a given character from string without using find() function Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Write a program in python to insert ten friends name in a list, then print 3rd, 5th and 9th value from the list (using data structure) Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    Write a C program to accept an integer number between 1 and 9. Write the value of the number in words. Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    write a program to print fibonacci series . write a program to search an element within the array using binary search Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    Considering the following sorted array and the search key as 89, what will be the sequence of keys in the array ... searching for 89? Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    write a Java program to input 10 non-zero numbers in an array and display the count of even and odd numbers. URGENT! Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    write a html program to display a menu card of Hotel debri with heading with atleast 3 veg and non veg ... checkboxes and place order Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    Q3: Write a program to subtract a matrix from another both have order 3*3. Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    Write error message given by C compiler during compilation if we use %d to print float variable Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Which key is used in combination with another key to perform a specific task ? (A) function (B) space bar (C) ... (E) None of these Select the correct answer from above options...
asked Dec 9, 2021 in Education by JackTerrance
0 votes
    Which key is used in combination with another key to perform a specific task ? (A) function (B) space bar (C) ... (E) None of these Select the correct answer from above options...
asked Dec 3, 2021 in Education by JackTerrance
0 votes
    state the various functions political parties perform in a democracy Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    To modify a formula in excel use __________ key. a) F11 b) F7 c) F2 Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    Write a program to prompt the user for days and rate per day to compute total pay. Use 50 days and a rate ... the string to a number. Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
...