Consider the following integer array of size 10, int array[10]={1,2,3,5,8,10,12,23,28,15} Write a c++ program that takes an integer value from the user at runtime and finds that value in the given array. If the value is found display message "Number is found" else display message "number does not found".
Code:
#include <iostream>
using namespace std;
int main()
{
for (int i=1;i<=2;i++)
{
int array[10]={1,2,3,5,8,10,12,23,28,15};
int num;
cout<<"Enter any digit : ";
cin>>num;
bool found=false;
for (int i=1;i<=10;i++)
{
if (array[i]==num)
{
found=true;
break;
}
}
if (found)
{
cout<<"Number found"<<endl;
}
else
{
cout<<"Number not found"<<endl;
}
}
return 0;
}
Result:
Comments
Post a Comment