Number of elements in array as input from user and store it in a variable N. Using a loop, take N numbers as input from user and store it in array. Ask user to enter element to be searched let if be num. If num is equal to any array element then print.
This program allows the user to enter the size of an array and its elements, and then searches for a specific value in the array:
Note that this program only searches for the first occurrence of x in the array. If there are multiple occurrences of x, only the first one will be reported.
#include<iostream> using namespace std; //Program to find a number in an array. int main() { int a[100],n,i,x; cout<<"\nEnter The Limit: "; cin>>n; for(i=0;i<n;i++) { cout<<"\nEnter The Value : "; cin>>a[i]; } cout<<"\nEnter The Value to Search :"; cin>>x; for(i=0;i<n;i++)//1 2 3 4 5 { if(a[i]==x) { cout<<"Value Found @"<<i; return 0; } } cout<<"Value Not Found"; return 0; }
Enter The Limit: 5 Enter The Value : 23 Enter The Value : 45 Enter The Value : 56 Enter The Value : 78 Enter The Value : 45 Enter The Value to Search :56 Value Found @2To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions