Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program called s earch Linear . c that prompts the user for 10 positiv

ID: 3921985 • Letter: W

Question

Write a C program called s earch Linear . c that prompts the user for 10 positive integers entered in any order and stores them in an array of integers . The program then prompts the user again to search for a value s in the array that either does or doesn't exist in the array . Next the program iterates through the array field by field and compares the stored value in the array with the element it needs to search. If a ma t ch occurs the index of the matched element will be printed to the screen in a suitable text message. Otherwise, an error message will b e printed to the screen indicating that the searched element does not exist among the entered values. The program then terminates.

Explanation / Answer

#include <stdio.h>
int main() {
int arr[10],key,i;
boolean flag=false;
printf("Enter 10 elements in array ");
for (i= 0; i< n; i++)

scanf("%d", &arr[i]);

printf("Enter the number/key to search ");
scanf("%d", &key);   
for (i= 0; i< n; i++)
{
if (arr[i] == key)
{
flag=true;
printf("%d is present at location %d. ",key,i+1);

break;
}
}
if (flag==false)
printf("%d is not present in array. ",key);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote