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
  • Write the code that will print out all elements in the int array called numbers, separated...

    Write the code that will print out all elements in the int array called numbers, separated by spaces, and a newline character after all elements are printed.

  • Write C++ statements that will print out how many of the elements in array numbers are...

    Write C++ statements that will print out how many of the elements in array numbers are divisible by 3. Given array filled with values: int numbers[12]; TTT Arial • 3(121) #T.EE Pathp Words:0

  • Write a C++ function binsearch that carries out the binary search algorithm on a sorted array...

    Write a C++ function binsearch that carries out the binary search algorithm on a sorted array of integers. Your function takes as parameters an array of integers (sorted in increasing order), the size of the array, and a target integer to search for. The function returns the index of the target in the array, and returns -1 if the target is not in the array. The file main1.txt on the webpage contains code that generates a specific array of integers...

  • This assignment will let me know if you have less than, greater than or equal to...

    This assignment will let me know if you have less than, greater than or equal to 50 cents in your pocket. Assuming the value you pulled out of your pocket is less than $1.00 •       In the main code, create 3 variables, 1st one will be "hard coded", meaning it will always have the same value when the program is ran. 2nd value is a value you input into the computer, 3rd value is a random number generated by the computer...

  • This assignment will let me know if you have less than, greater than or equal to...

    This assignment will let me know if you have less than, greater than or equal to 50 cents in your pocket. Assuming the value you pulled out of your pocket is less than $1.00 •       In the main code, create 3 variables, 1st one will be "hard coded", meaning it will always have the same value when the program is ran. 2nd value is a value you input into the computer, 3rd value is a random number generated by the computer...

  • E2.15 In assembly code, write a program to count the number of elements in an array...

    E2.15 In assembly code, write a program to count the number of elements in an array that are smaller than 16. The array is stored at memory locations starting from $1010. The array has 30 8-bit unsigned elements. Store the count in the memory location $C001.

  • F a as a sequence of adjacent array elements such that each value in the run array was of size 10...

    f a as a sequence of adjacent array elements such that each value in the run array was of size 10 9. We define a "run" of elements o (except for the first) is one greater than the previous and looked like: value. For example, say the 3 2 16 9 7 8 9 2 a: position 0 3 We have three runs in this array: (1) between 9,10,1, 12) and, (3) between positions 7 and 8, (15, 16) positions...

  • C Language Write the code that dynamically allocates an array of struct objects based on a...

    C Language Write the code that dynamically allocates an array of struct objects based on a size entered through the command line arguments, You will use the following struct and enum. typedef enum Color { RED, GREEN, BLUE } Color; typedef struct MyStruct { int value; Color color; } MyStruct; Write the code to do the following: a. Check for one additional command line argument. Only proceed to the rest of the program if it exists and that the value...

  • Write a Main function and a Function to compute and print the sine and cosine values...

    Write a Main function and a Function to compute and print the sine and cosine values of the array A elements which are angles in degrees. Within the MAIN function: • Declare a float array A to hold 50 angles in degrees. • Initialize array A elements from the standard input. • Pass the array A to the function as an argument. Within the function: • Read array A elements and compute and print the sine and cosine values of...

  • c++ Given the following code: int number = 50; Write the if statement to print “yes” and add...

    c++ Given the following code: int number = 50; Write the if statement to print “yes” and add one to the number variable if the value stored in the number variable is greater than 50 or less than or equal to 75.

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