1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anna35 [415]
3 years ago
12

Write a function, in the programming language of your choice, which finds contiguous regions (or "islands") in a matrix where al

l values in the island are greater than a threshold (but not necessarily the same). The function should take a threshold, a minimum island size, and an arbitrarily sized matrix as inputs. The function should output a matrix (same size as the input matrix) of booleans. Do not wrap around matrix edges. Corner neighbors are not sufficient for island continuity. For example, if the the inputs are: threshold = 5, min island size = 3, and matrix = [4, 4, 4, 2, 2; 4, 2, 2, 2, 2; 2, 2, 8, 7, 2; 2, 8, 8, 8, 2; 8, 2, 2, 2, 8]. Then the output would be [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 1, 1, 0; 0, 1, 1, 1, 0; 0, 0, 0, 0, 0].
Engineering
1 answer:
ExtremeBDS [4]3 years ago
4 0

Answer:

#include <stdio.h>

int main()

{

int threshold = 5;

int i,j;

int matrix[5][5] = {{4, 4, 4, 2, 2},

{4, 2, 2, 2, 2},

{2, 2, 8, 7, 2},

{2, 8, 8, 8, 2},

{8, 2, 2, 2, 8}};

int row=(sizeof(matrix)/sizeof(matrix[0])); // length of row

int column=(sizeof(matrix)/sizeof(matrix[0][0]))/row; // length of column

printf("Input matrix value:\n");

for(i=0; i <5; i++)  

{

for(j=0; j<5; j++)

{

printf("%d ", matrix[i][j]);

}

printf("\n");

}

printf("\n");

for(i=0; i<column; i++)  

{

for(j=0; j<column; j++)

{

if ( (j == 0) || (j == column-1) ) // print 0 for first and last element of every row

printf("%d ", 0);

else

{

if(matrix[i][j] > threshold) // veify whether the element is more than threshold

{

printf("%d ",1);

}

else

{

printf("%d ", 0);

}

}

}

printf("\n");

}

return 0;

}

You might be interested in
Since 1990, hand-held mobile phones have been used as communication devices. Mobile phones have gone through a lot of design cha
Alexxx [7]

Answer: IMPACT: Access to the mobile web was a major improvement for cell phones in the 1990s. With 2G (digital cellular networks), came the ability to access media content and the World Wide Web on cell phones.

Explanation:

8 0
3 years ago
A lake is fed by a polluted stream and a sewage outfall. The stream and sewage wastes have a decay rate coefficient (k) of 0.5/d
joja [24]

Solution :

Given :

k = 0.5 per day

$C_s = 10 \ mg/L \ ; \ \ Q_s= 40 \ m^3/s$

$C_{sw} = 100 \ ppm \ ; \ \ Q_{sw}= 0.5 \ m^3/s$

Volume, V $= 200 \ m^3$

Now, input rate = output rate + KCV ------------- (1)

Input rate  $= Q_s C_s + Q_{sw}C_{sw}$

                $=(40 \times 10) + (0.5\times 100)$

                $= 2 \times 10^5 \ mg/s$

The output rate $= Q_m C_{m}$

                          = ( 40 + 0.5 ) x C x 1000

                          $=40.5 \times 10^3 \ C \ mg/s$

Decay rate = KCV

∴$KCV =\frac{0.5/d \times C \  \times 200 \times 1000}{24 \times 3600}$

            = 1.16 C mg/s

Substituting all values in (1)

$2 \times 10^5 = 40.5 \times 10^3 \ C+ 1.16 C$

C = 4.93 mg/L

4 0
3 years ago
Three spheres are subjected to a hydraulic stress. The pressure on spheres 1 and 2 is the same, and they are made of the same ma
r-ruslan [8.4K]

Answer:

"150000 N/m²" is the right approach.

Explanation:

According to the question, the pressure on the two spheres 1 and 2 is same.

Sphere 1 and 2:

Then,

⇒  P_1=P_2

⇒  \frac{\Delta V_1}{V_1}=\frac{\Delta V_2}{V_2}

and the bulk modulus be,

⇒  B_1=B_2

Sphere 3:

⇒  \frac{\Delta V_3}{V_3} =\frac{\frac{\Delta V_1}{V_1} }{\frac{\Delta V_2}{V_2} } =1

then,

⇒  P_3=B\times \frac{\Delta V_3}{V_3}

⇒       =B\times 1

⇒       =150000\times 1

⇒       =150000 \ N/m^2

5 0
3 years ago
LAB 3.3 – Working with String Input and Type CastingStep 1: RemovefindErrors.cppfrom the project and add thepercentage.cppprogra
jolli1 [7]

Answer:

// Program is written in C++ Programming Language

// Comments are used for explanatory purpose

#include<iostream>

using namespace std;

int main ()

{

// Variable declaration

string name;

int numQuestions;

int numCorrect;

double percentage;

//Prompt to enter student's first and last name

cout<<"Enter student's first and last name";

cin>>name; // this line accepts input for variable name

cout<<"Number of question on test"; //Prompt to enter number of questions on test

cin>> numQuestions; //This line accepts Input for Variable numQuestions

cout<<"Number of answers student got correct: "; // Prompt to enter number of correct answers

cin>>numCorrect; //Enter number of correct answers

percentage = numCorrect * 100 / numQuestions; // calculate percentage

cout<<name<<" "<<percentage<<"%"; // print

return 0;

}

Explanation:

The code above calculates the percentage of a student's score in a certain test.

The code is extracted from the Question and completed after extraction.

It's written in C++ programming language

4 0
4 years ago
Consider an ideal gas undergoing a constant pressure process from state 1 to state
Radda [10]

Answer:

s_2-s_1=c\frac{T^d}{d}-Rg\ ln(\frac{P_2}{P_1})

Explanation:

Hello,

In this case by combining the first and second law of thermodynamics for this ideal gas, we can obtain the following expression for the differential of the specific entropy <em>at constant pressure</em>:

ds=c_p\frac{dT}{T}-Rg\ \frac{dP}{P}

Whereas Rg is the specific ideal gas constant for the studied gas; thus, integrating:

\int\limits^{s_2}_{s_1} {} \, ds=c\int\limits^{T_2}_{T_1} {T^{d-1}dT} \,-Rg\ \int\limits^{P_2}_{P_1} {\frac{dP}{P}} \,

We obtain the expression to compute the specific entropy change:

s_2-s_1=c\frac{T^d}{d}-Rg\ ln(\frac{P_2}{P_1})

Best regards.

6 0
4 years ago
Other questions:
  • What is an aqueduct?
    6·2 answers
  • When comparing solids to fluids, the following is true: for elastic solids, the stress must be normal. For Newtonian fluids, the
    9·1 answer
  • Fred wants to help his customer understand his vision for constructing the office interior. Which visual representation will bes
    8·1 answer
  • Why/how is a paperclip able to float on water?
    9·1 answer
  • Which option distinguishes what can be inferred from the following scenario?
    14·1 answer
  • 1. When should a synthetic oil change be completed? *
    13·2 answers
  • The four important principles of flight are lift, drag, thrust, and _____.
    7·1 answer
  • The total number of species in an area is termed as<br>​
    6·2 answers
  • Electricity is the flow of electrons from a negatively charged
    8·1 answer
  • A mass of 2.4 kg of air at 150 kPa and 12ºC is contained in a gas-tight, frictionless piston-cylinder device. The air is now com
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!