Question

Code in C++ please! Write a function that takes an array of integers as an input...

Code in C++ please!

Write a function that takes an array of integers as an input parameter (the address of the first value of the array). It returns nothing. It prints out the array as a single line, with commas between each number, and when the array is finished being printed, it prints an endl; so that we flush the buffer and move to a new line. (I’m having you write this function because you’ll be wanting to print out arrays a lot in the following exercises).

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

void print_array(int *arr, int size) {
    for(int i = 0; i < size; ++i) {
        cout << arr[i];
        if(i != size-1) {
            cout << ", ";
        }
    }
    cout << endl;
}

int main() {
    int arr[] = {4, 3, 5, 6, 2, 1};
    print_array(arr, 6);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Code in C++ please! Write a function that takes an array of integers as an input...
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