Ask Question
1 September, 04:29

Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void. It should look like this {5,10,8,9,1}

+3
Answers (1)
  1. 1 September, 04:34
    0
    void printarr (int nums[], int n)

    {

    cout<<"{"; //printing { before the elements.

    for (int i=0; i
    {

    cout<
    if (i==n-1) / /if last element then come out of the loop.

    break;

    cout<<","; //printing the comma.

    }

    cout<<"}"<
    }

    Output:-

    5

    1 2 3 4 5

    {1,2,3,4,5}

    Explanation:

    I have created a function printarr of type void which prints the array elements in one line. I have used for loop to iterate over the array elements. Everything else is mentioned in the comments.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void. It should ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers