Write a C program called s earch Linear c that prompts the
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.
Solution
#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;
}
