Answer to Question #349901 in C++ for Magisk

Question #349901

Instructions:

  1. Declare and define display() function with the ff. details:
  2. Return type - void
  3. Name - display
  4. Parameters
  5. int* - an array
  6. int - the size of an array

Given code

#include <iostream>

using namespace std;


// TODO: Declare the display() function here



int main(void) {

  int world[100] = {

    1,3,2,4,5,7,6,8,9,11,

    100,13,0,14,16,17,3,18,20,10,

    12,8,15,14,-5,17,19,18,1,9,5,

    10,13,11,14,16,22,0,18,20,3,

    99,13,15,14,22,17,19,0,23,2,

    12,13,15,22,16,17,56,18,44,99,

    2,13,22,14,16,89,19,69,101,34,

    12,22,15,14,78,17,69,18,2,33,

    4,13,77,7,10,17,19,91,4,22,

    12,98,15,14,15,17,19,18,7

  };


  display(world, 100);

   

  return 0;

}


// TODO: Define the display() function here


Ex

Element·at·index·0:·1

Element·at·index·1:·3

Element·at·index·2:·2

Element·at·index·3:·4

.

.

.



1
Expert's answer
2022-06-13T08:27:39-0400
#include <iostream>
using namespace std;

// TODO: Declare the display() function here
void display (int *arr, int n);

int main(void) {

  int world[100] = {

    1,3,2,4,5,7,6,8,9,11,

    100,13,0,14,16,17,3,18,20,10,

    12,8,15,14,-5,17,19,18,1,9,5,

    10,13,11,14,16,22,0,18,20,3,

    99,13,15,14,22,17,19,0,23,2,

    12,13,15,22,16,17,56,18,44,99,

    2,13,22,14,16,89,19,69,101,34,

    12,22,15,14,78,17,69,18,2,33,

    4,13,77,7,10,17,19,91,4,22,

    12,98,15,14,15,17,19,18,7

  };

  display(world, 100);

  return 0;
}
void display (int *arr, int n){
    int i;
    for(i=0;i<n;i++){
        cout<<"Element at index "<<i<<"; "<<*(arr+i)<<endl;
    }
}

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
APPROVED BY CLIENTS