Ask Question
31 March, 04:43

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}

+1
Answers (1)
  1. 31 March, 06:53
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers