Question

In: Computer Science

Using c++ to find all the peaks elements in a 2d array, each element has eight...

Using c++ to find all the peaks elements in a 2d array, each element has eight neighbours

Solutions

Expert Solution

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

#include <iostream>

int main()

{

    constexpr int numRows{ 10 };

    constexpr int numCols{ 10 };

    // Declare a 10x10 array

    int product[numRows][numCols]{};

    // Calculate a multiplication table

    for (int row{ 1 }; row < numRows; ++row)

    {

        for (int col{ 1 }; col < numCols; ++col)

        {

            product[row][col] = row * col;

        }

     }

    // Print the table

    for (int row{ 1 }; row < numRows; ++row)

    {

        for (int col{ 1 }; col < numCols; ++col)

        {

            std::cout << product[row][col] << '\t';

        }

        std::cout << '\n';

}

    return 0;

}

This program calculates and prints a multiplication table for all values between 1 and 9 (inclusive). Note that when printing the table, the for loops start from 1 instead of 0. This is to omit printing the 0 column and 0 row, which would just be a bunch of 0s! Here is the output:

1    2    3    4    5    6    7    8    9
2    4    6    8    10   12   14   16   18
3    6    9    12   15   18   21   24   27
4    8    12   16   20   24   28   32   36
5    10   15   20   25   30   35   40   45
6    12   18   24   30   36   42   48   54
7    14   21   28   35   42   49   56   63
8    16   24   32   40   48   56   64   72
9    18   27   36   45   54   63   72   

Related Solutions

Send an element from 2d array to a function using pointer to pointer. c++ I am...
Send an element from 2d array to a function using pointer to pointer. c++ I am having an issue with being able to send specific elements to the swap function. #include <iostream> using namespace std; void swap(int **a, int **b){    int temp = **a;    **a=**b;    **b=temp; } void selSort(int **arr, int d){    for(int i =0; i<d-1; i++){        int min = *(*arr+i);        int minin = i;        for(int j =i+1; j<d; j++){...
write a recursive algorithm to find the maximum element in an array of n elements and...
write a recursive algorithm to find the maximum element in an array of n elements and analyze its time efficiency. (I am using c++ programming language)
Python. The array C has multibel peaks (+ , -). write a code that detect the...
Python. The array C has multibel peaks (+ , -). write a code that detect the vlaues of all those peaks. C = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0011 -0.0031 0.0011 0.0034 -0.0039 0.0004 0.0052 -0.0045 -0.0025 0.0067 -0.0038 -0.0034 0.0077 -0.0034 -0.0054 0.0076 -0.0011 -0.0063 0.0068 0.0004 -0.0084 0.0061 0.0037 -0.0086 0.0018 0.0063 -0.0045 -0.0069 0.0078 0.0027 -0.0132 0.0054 0.0133 -0.0131 -0.0060 0.0180 -0.0037 -0.0169 0.0140 0.0128 -0.0210...
Overlapping Arrays (C++) An array overlaps another array if all elements of the latter array exist...
Overlapping Arrays (C++) An array overlaps another array if all elements of the latter array exist in the former array. They need not necessarily be in the same order. For example, [1,7,3,4,2] overlaps [1,2,3] because 1,2 and 3 exist in [1,7,3,4,2]. To make the implementation easy, [1,7,3,4,2] overlaps [1,1,2,3] as well. We don’t need to check whether 1 appears twice in the first array. Write a program that lets the user enter two arrays and displays whether the first array...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Create a brief argument using all the Toulmin elements and label each element in your argument.
Create a brief argument using all the Toulmin elements and label each element in your argument.
Consider the element uniqueness problem: check whether all the elements in a given array of n...
Consider the element uniqueness problem: check whether all the elements in a given array of n elements are distinct answer in pseudo code places
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array...
THE FOLLOWING IS CODED IN C Write a function that sets each element in an array to the sum of the corresponding elements in two other arrays. That is, if array 1 has the values 2,4, 5, and 8 and array 2 has the values 1, 0, 4, and 6, the function assigns array 3 the values 3, 4, 9, and 14. The function should take three array names and an array size as arguments. Test the function in a...
Lab 7 - 2D Arrays (C++) In main, declare and fill a 2D array with one...
Lab 7 - 2D Arrays (C++) In main, declare and fill a 2D array with one hundred rows and fifty columns. Iterate through each element and assign it a random value between -72 and 75 inclusive. Have your random number seed be 25. Create functions that do the following: 1. A function called “sum” that returns the sum of all the elements in your 2D Array. 2. A function called “average” that return the average value of the elements in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT