Make a program that will accept an integer and loop for the same number of times as that of the inputted integer and input random integers and add it to the array/list one by one, per line. Afterwards, make your program accept another random integer.
Using that final integer, compare from your array/list if the final integer's value is also present in your current array/list. If so, print "Present"; otherwise, print "None".
#include <iostream>
#include <vector>
bool is_prime (int number)
{
for( int i = 2; i != number; ++i)
{
if(number % i == 0)
{
return false;
}
}
return true;
}
int main()
{
int number = 0;
std::cout<<"Enter number: ";
std::cin>>number;
std::vector<int> inputted_values(number);
for(int i = 0; i != number; ++i)
{
std::cin>>inputted_values[i];
}
std::cout<<"Enter another random integer: ";
std::cin>>number;
std::vector<int>::iterator found = std::find(inputted_values.begin(), inputted_values.end(), number);
if(found == inputted_values.end())
{
std::cout<<"None"<<std::endl;
}
else
{
std::cout<<"Present"<<std::endl;
}
return 0;
}
Comments
Leave a comment