Question

IN C++ Write a code to print out elements from a array/vector that is greater/less than...

IN C++

Write a code to print out elements from a array/vector that is greater/less than a specific value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//print out elements from a array that is greater than a specific value.
void printArray(int array[], int size, int key){
    for(int i = 0;i<size;i++){
        if(array[i]>key){
            cout<<array[i]<<" ";
        }
    }
}

//print out elements from a array that is less than a specific value.
void printArray(int array[], int size, int key){
    for(int i = 0;i<size;i++){
        if(array[i]<key){
            cout<<array[i]<<" ";
        }
    }
}

//print out elements from a vector that is greater than a specific value.
void printArray(vector<int> vec, int key){
    for(int i = 0;i<vec.size();i++){
        if(vec[i]>key){
            cout<<vec[i]<<" ";
        }
    }
}

//print out elements from a vector that is less than a specific value.
void printArray(vector<int> vec, int key){
    for(int i = 0;i<vec.size();i++){
        if(vec[i]<key){
            cout<<vec[i]<<" ";
        }
    }
}
Add a comment
Answer #2
//print out elements from a array that is greater than a specific value.
void printArray(int array[], int size, int key){
    for(int i = 0;i<size;i++){
        if(array[i]>key){
            cout<<array[i]<<" ";
        }
    }
}

//print out elements from a array that is less than a specific value.
void printArray(int array[], int size, int key){
    for(int i = 0;i<size;i++){
        if(array[i]<key){
            cout<<array[i]<<" ";
        }
    }
}

//print out elements from a vector that is greater than a specific value.
void printArray(vector<int> vec, int key){
    for(int i = 0;i<vec.size();i++){
        if(vec[i]>key){
            cout<<vec[i]<<" ";
        }
    }
}

//print out elements from a vector that is less than a specific value.
void printArray(vector<int> vec, int key){
    for(int i = 0;i<vec.size();i++){
        if(vec[i]<key){
            cout<<vec[i]<<" ";
        }
    }
}


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
IN C++ Write a code to print out elements from a array/vector that is greater/less than...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT