Ask 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 look like this {5,10,8,9,1}

+4
Answers (1)
  1. 29 November, 07:56
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers