Answer to Question #185512 in C++ for Woyengimiesindo

Question #185512

Write a function that displays the contents of an array in a predefined format with 

the value of index 0, displayed last.



1
Expert's answer
2021-05-01T23:32:36-0400
#include <iostream>
using namespace std;


template <typename T, int n> 
void display_content (T const(& arr)[n])
{
    for (int i = 1; i < n; i++) 
    {
        cout << arr[i] << ", ";
    }
    cout<< arr[0]<<endl;
 }


int main()
{
    //example work function display_content
    int test[] = { 17,25,48,98 };
    display_content(test);
    double test_11[] = { 3.2,7.8,9.87,99,104 };
    display_content(test_1);
    char test_2[] = "abcfd";
    display_content(test_2);
    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