Respuesta :
Answer:
The program to this question can be given as:
Program:
//header file
#include <stdio.h>
void search(int n) //define function.
{
int a[n],find,i; //variable declaration
printf("Enter elements of array :\n"); //message
for (i = 0; i <n; i++) //loop
{
scanf("%d", &a[i]); //input array elements
}
printf("Enter a number to search: ");
scanf("%d", &find); //input number for search
for (i = 0; i< n; i++) //search number.
{
if (a[i] == find) //if element is found in array
{
printf("%d is present at location %d.\n",find,i+1); //print location.
}
}
}
int main() //main method
{
int n; //variable declaration
printf("Enter size of array: "); //message
scanf("%d", &n); //input sizeof array.
search(n); //calling function.
return 0;
}
Output:
Enter size of array: 6
Enter elements of array :
4
2
1
4
2
4
Enter a number to search: 4
4 is present at location 1.
4 is present at location 4.
4 is present at location 6.
Explanation:
In the above C language program firstly we define the header file that is stdio.h this header file is used to take stander input output from the user.
Then we define the main function. In this function, we declare a variable that is search, n, and i. In this, we also declare an array variable that is a[].
After inserting all array elements we take a number from the user to search number that is present in the array or not.
For this process, we define a loop. In this loop, we define a conditional statement in this if block we check elements of the array equal to search variable if this condition is true so it will print the position of number that is found in the array.