C program to find given element in array
So far we have seen how to take input in array and printing the same. We have got knowledge, how to scan an array ? Right… In this post we are finding an element if it found then we have to print its position otherwise say “Element not found “. We have read the relational operators which are used to compare values.
step 0 : initialize found variable as 0 means notfound
step1: Input the array and value to be searched
Step2 : Scan the array from start position to size of array
— check for equality of array element (arr[i] ) and search value (findval) using (arr[i]==findval)
— above condition is true then initialize fount=1 and break the loop
step3 : if found==1 then print the found value and position too.
printf("n Enter the size of array to be taken input [max 100]: ");
// A loop for input array
printf("Enter the Element No %d : ",i+1);
printf("nEnter the value to be searched : ");
/* To find element in array we must compare each cell in array and if match is found we must stop */
printf("n Value is found at position : %d ",i+1);
else printf("n No match found ");
C program to find given element in array.