c++ program to search a number in array

#include<iostream>
using namespace std;
void search_array(int arr[],int num);
int main()
{
int num,arr[100];
cout<<“Enter the size of the arrayn”;
cin>>num;
cout<<“Enter elements in the arrayn”;
for(int i=0;i<=num;i++)
{
cin>>arr[i];
}
search_array(arr,num);
}
void search_array(int arr[],int num)
{
int i,number,flag=0;
cout<<“Enter the number to search in the arrayn”;
cin>>number;
for(i=0;i<=num;i++)
{
if(arr[i]==number)
flag=1;
}
if(flag==1)

cout<<“Found in index “<<i;//i to display index number of array
else
cout<<“Not found”;

}
OUT:
Enter the size of the array
2
Enter elements in the array
45
47
12
Enter the number to search in the array
12
Found in index 3

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat