I\'m completely stuck trying to write a complete C Language program that sequent
ID: 666089 • Letter: I
Question
I'm completely stuck trying to write a complete C Language program that sequentially searches a one-dimensional array of elements for a specific value. The program should use a user defined function to prompt the user to enter an array of 10 elements. The program should also ask the user to specify a target value to search for. A user defined function should be used to search the array. If the target value is found, the program should return the array index associated with it. Otherwise, the program should display a message indicating that the target value was not found.
Explanation / Answer
#include <stdio.h>
int main()
{
int i,n,a[10],flag=1;
for(i=0;i<10;i++){
printf("Enter the %d element of the array:",(i+1));
scanf("%d",&a[i]);
}
printf(" enter the number to be found");
scanf("%d",&n);
for(i=0;i<10;i++){
if(n==a[i]){
printf(" element found %d at index:%d",a[i],i);
flag=0;
}
}
if(flag==1){
printf(" element not found on the entire array");
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.