Write a program to find a numebr in arrya using if statment c++ find index of element in array

 Linear search is the simplest searching algorithm which is sometimes known as sequential search.C++ program to is one-dimensional array of integers.Basic programming example C++ linear search code for beginners



#include <iostream>

using namespace std;

int main()

{

int b;

int ary[5];

int findnumber;

int f = 0;



for (int q = 0; q < 5; q++)

{

cout << "Enter you " << q + 1 << " Number\n";

cin >> ary[q];

}

cout << "\tEnter you number you want to find \n";

cin >> findnumber;

for ( b = 0; b < 5; b++)
{

if (findnumber == ary[b])

{

f = 1;

break;
}

else

{
f = 0;

}

}

if (f == 1)

{
cout << "your number is found :) \n";

cout << "your found number place in the array is \n"<<b+1;

}

else
{

cout << "number not found :( \n";

}

system("pause");

}
Previous
Next Post »