Question

How to compact a randomly space a 2d array in c++? May you write comments please.

How to compact a randomly space a 2d array in c++? May you write comments please.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {
    int rows = 10, cols = 10;
    int arr[10][10];
    // generate random array
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            arr[i][j] = rand() % 1000;
        }
    }
    // print random array
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            cout << arr[i][j] << "\t";
        }
        cout << endl;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
How to compact a randomly space a 2d array in c++? May you write comments please.
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please code using C++ Thank you Write a function that receives a 2d array of type...

    Please code using C++ Thank you Write a function that receives a 2d array of type double and returns the average of all elements in the 2d array

  • JAVA / please add comments Write code for a method named loadDatagrams() that returns an array...

    JAVA / please add comments Write code for a method named loadDatagrams() that returns an array of type Datagram. The method will read from the filepath C:/folder/grams.dgf and the file contains an array of type Datagram ( you may assume that the class definition is visible to the method) Remember to include appropriate exception handling

  • Write a C program that uses mallloc to create a 2D array. of c columns and...

    Write a C program that uses mallloc to create a 2D array. of c columns and r rows. Elements of array must be initialized to 0 and you must use malloc and free allocated memory fo array.

  • Write c++ program In this assignment, you need to complete following tasks on 2D array of...

    Write c++ program In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manager of coffee shop chain, and oversee 5 branches. ID of branches are 1 to 5. You already collected sales data for yesterday from each branch, in three categories: morning, afternoon, and evening. First, you need to create a 2D array (5x3) with random numbers between 300 and 1000 (including 300 and 1000), i.e., from $300...

  • Write c++ program In this assignment, you need to complete following tasks on 2D array of...

    Write c++ program In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manager of coffee shop chain, and oversee 5 branches. ID of branches are to 5. You already collected sales data for yesterday from each branch, in three categories: morning, afternoon, and evening. First, you need to create a 2D array (5x3) with random numbers between 300 and 1000 (including 300 and 1000), i.e., from $300 to...

  • In C++ for 2D Array: Write a program that uses a function that manipulates a 2D...

    In C++ for 2D Array: Write a program that uses a function that manipulates a 2D array of integers as follows: 1. Fill the first row and column in the array with random bits 2. Every subsequent cell should be filled as follows: 1. If the cells that are to the left and top of it are equal, then you should store their sum in it b. Otherwise, your program should store the highest among them. Test your function using...

  • c++ please Instructions In this assignment, you need to complete following tasks on 2D array of...

    c++ please Instructions In this assignment, you need to complete following tasks on 2D array of randomly sales figures. Assume that you are the manager of coffee shop chain, and oversee 5 branches. ID of branches are 1 to 5. You already collected sales data for yesterday from each branch, in three categories: morning, afternoon, and evening. First, you need to create a 2D array (5x3) with random numbers between 300 and 1000 (including 300 and 1000), i.e., from $300...

  • Python: Write a function "contrast_adjust", which takes a 2D NumPy array A and an integer c,...

    Python: Write a function "contrast_adjust", which takes a 2D NumPy array A and an integer c, and returns another NumPy array of the same size, representing the contrast-adjusted image. You can assume that −127 ≤ c ≤ 127.

  • please write this code in c++ // a: an array of ints. size is how many...

    please write this code in c++ // a: an array of ints. size is how many ints in array 7/ Return the largest value in the list. 7/ This value may be unique, or may occur more than once // You may assume size >= 1 int largestValue(int *a, int size) { assert(size >= 1); return -42; // STUB !!! Remove and replace with correct code 71 a: an array of ints. size is how many ints in array 7/...

  • write a program of c++ that will loop through a 2D array of size 2*3 ,...

    write a program of c++ that will loop through a 2D array of size 2*3 , and prints it out in a block of number.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT