Answer to Question #285085 in C for Ehziii

Question #285085

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".


1
Expert's answer
2022-01-06T02:01:42-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS