Question

Write a c++ function which takes two parameters: an array of ints and an int size...

Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature:

void printSome(const int array[], int size);

Homework Answers

Answer #1
#include <iostream>

using namespace std;

void printSome(const int array[], int size);

int main() {
    int arr[] = {9, 1, 2, 7, 4, 10, 6}, size = 7;
    printSome(arr, size);
    return 0;
}

void printSome(const int array[], int size) {
    for (int i = 0; i < size; ++i) {    // go through each element in array
        if (array[i] > 5)   // if an element is larger than 5
            cout << array[i] << endl;   // then print it
    }
}

Know the answer?
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
Similar Questions
The c++ question: Assume that there is a valid file cards.txt in the current directory which...
The c++ question: Assume that there is a valid file cards.txt in the current directory which contains 5 valid int values, each on its own line. Write a function which reads all the values from the file and prints out the message “Lucky 7!” to the screen for every 7 it sees. Your function must have the following signature: void printSevens();
Write a function that takes an array of integers and its size as parameters and prints...
Write a function that takes an array of integers and its size as parameters and prints the two largest values in the array. In this question, the largest value and the second largest value cannot be the same, even if the largest value occurs multiple times. In the first sample, the two largest values are 9 and 8 (even though the value 9 appears twice). In the second sample, all the values are equal and the program recognizes this by...
Write a function named “highestScore” that takes an array of floating point scores and its size...
Write a function named “highestScore” that takes an array of floating point scores and its size as parameters and return the highest of these scores. The function prototype: float highestScore(float scores[], int size);
In C Not C++ write a function that takes in the reference of an int array...
In C Not C++ write a function that takes in the reference of an int array and return the value -1 if sum is odd, and 1 if the sum is even.
In main.cpp, write a templated function more which takes in two variables of the same type...
In main.cpp, write a templated function more which takes in two variables of the same type and returns whichever variable is greater than (>) the other. You can and may need to add something to the food class in order for more to be able to be called properly. //food.h #ifndef _FOOD_H #define _FOOD_H #include <iostream> #include <string> using namespace std; class Food { private: string name; int quantity; public: Food(); void setName(string newName); void setQuantity(int newQuantity); string getName(); int...
1. Assume there was a valid file called cards.txt in the current directory containing 5 valid...
1. Assume there was a valid file called cards.txt in the current directory containing 5 valid int values, each on its own line. It is needed to write the function that reads all values from file and then prints out: "lucky 7!" to the screen for every 7 it sees. Use the signature: void printSevens();
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Write a function that accepts an int array arr, the array’s size sz and integer n,...
Write a function that accepts an int array arr, the array’s size sz and integer n, the function should create a new array that it’s n times the array arr. The fucntion copy the content of arr to the new array n times. The Example arr = {5, 2, 1} n=3 Newarr = {5, 2, 1, 5, 2, 1, 5, 2, 1} (c++)
Please create an array of Leg objects, one constructor that takes three parameters as constant C...
Please create an array of Leg objects, one constructor that takes three parameters as constant C string, and one number representing the distance in miles between the two cities Write a code block to create a static array (that is, not dynamic and not a vector) of 3 Leg objects using city names of your choosing. That's THREE objects, each created using THREE parameters. For example, the Leg class declaration looked like, class Leg { const char* const startCity; const...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT