Question

for C++, I am trying to create a function that prints a 2D array. Can you...

for C++, I am trying to create a function that prints a 2D array. Can you instruct me on the easiest way to do so? Please do not make it complicated, we have no started learning about pointers yet, either, so it can't be done that way.

Homework Answers

Answer #1

Please find the code below:

main.cpp

#include <iostream>
using namespace std;

void printTwoDArray(int array[][4]){
   cout<<"Content of array is as below"<<endl;
   for(int i=0;i<4;i++){
       for(int j=0;j<4;j++){
           cout<<array[i][j]<<" ";
       }
       cout<<endl;
   }
}

int main(){

   int array[4][4] = {{1,2,3,4},{4,5,4,5},{6,6,6,6},{7,7,7,7}};
   printTwoDArray(array);
   return 0;
}

output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Good day, I am trying to create a PICO question research question. Can you please give...
Good day, I am trying to create a PICO question research question. Can you please give me some examples that i can use? I am interested in newborn babies. Maybe something with home births vs hospital birth and an increase in death with babies? I am not sure. Please help.
Good day, I am trying to create a PICO question research question. Can you please give...
Good day, I am trying to create a PICO question research question. Can you please give me some examples that i can use? I am interested in newborn babies. Maybe something with home births vs hospital birth or water birth vs traditional birth and an increase in death with babies? I am not sure. Please help. Tell me what you want to find out/ what is your purpose of the research question.
UNITY QUESTION I am working with my team in Unity to create a character. I am...
UNITY QUESTION I am working with my team in Unity to create a character. I am responsible for creating a character's moves. Nothing really has been done yet, but could you provide an example of code using C# or C++ or even pseudocode Please provide functions for my character to go walk, run, move up, move down, move forward, and move backwards. I will give a thumbs up if it is decent :) Just give me an example code for...
I am experimenting with pointers in C. I wrote this code. int i1; int i2 =...
I am experimenting with pointers in C. I wrote this code. int i1; int i2 = 50; int *intptr1; int *intptr2; intptr1 = &i1; intptr2 = &i2; intptr1 = intptr2; printf("\nvalue of intptr1: %d\n", *intptr1); /*prints 50*/ dubptr1 = (double *)intptr1; printf("\nvalue of dubptr1: %f\n", *dubptr1); /*prints 0.0000*/ I would have expected the last statement to print 50.0000. Is it actually supposed to print 0.0000 or did I make a mistake somewhere and if I did please help me understand...
First issue: a) I am trying to create a SQL query so i can list all...
First issue: a) I am trying to create a SQL query so i can list all the items that a user has bought b)I am trying to show how much it will cost in total for user My tables: Table user(user_id, username, shipping_address) Table item(item_id, item, pricing) Table receipt(r_id, user_id, date_current) Table rDetailing(r_id, item_id, item_in, amount_of_item)
So I am trying to write a factor generator. User provides an integer and program needs...
So I am trying to write a factor generator. User provides an integer and program needs to return all factors. I have found an example the code that does this function, but I can't understand how it does that. Please explain line by line how this works.     System.out.print("Enter an integer: ");        int number = input.nextInt();        int index = 2; //Prompts user for an integer and assigns it to variable number, and integer index is declared...
Please create an array of Leg objects, one constructor that takes three parameters as constant C...
Please create an array of Leg objects, one constructor that takes three parameters as constant C string, and one number representing the distance in miles between the two cities Write a code block to create a static array (that is, not dynamic and not a vector) of 3 Leg objects using city names of your choosing. That's THREE objects, each created using THREE parameters. For example, the Leg class declaration looked like, class Leg { const char* const startCity; const...
USING JAVA: I was asked to write a function that obtains a name from the user...
USING JAVA: I was asked to write a function that obtains a name from the user and returns it in reverse order (So if the user inputs "MIKE" the function returns "EKIM"). You can't use string variables it can only be done using a Char Array. Additionally, you can use a temporary Char Array but you are supposed to return the reverse order in the same char array that the user input, this is for hypothetical cost purposes -we are...
So I am trying to make Blist array equal to a number between 89 and 80...
So I am trying to make Blist array equal to a number between 89 and 80 but when I use && Blist becomes empty (javascript) var Alist=[]; var Blist=[]; var Clist=[]; var Dlist=[]; var Flist=[]; for(var i=0;i<numbers.length;i++) //remov empty values { if(numbers[i] != "") numbers2.push(numbers[i]); } console.log("FIRST numbers2="+numbers2.toString()); for(var i=0;i<numbers2.length;i++) //remov empty values { if( parseInt(numbers2[i]) >= 90) Alist.push(numbers2[i]); } console.log("A LIST="+Alist.toString()); Alist.sort(function(a,b){return (a-b);}); Alist=Alist.join(' '); for(var i=0;i<numbers2.length;i++) //remov empty values { if( parseInt(numbers2[i]) <= 89 && parseInt(numbers2[i] >= 80))...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT