Question

ugi square Square. 1,000,000 times and see the number Ul ll dimensional board, of type int. An element board[i][j] is a peak (either aay, or a minimum) if all its neighbors (there should be either 3, 5, or 8 ncihitlh) for any cell) are less than board[ i][j], or greater than boa program should output all elements in board, with their indices, wh peak. It should also output if a peak is a maximum or a minimum. amaximum 21. Write a program that randomly generate a 20 x 20 two-dimer j1. The
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

Executable code

#include <stdio.h>
#include <stdlib.h>

int main() {
int array_size=20, i, j;
int array[array_size][array_size];
for(i=0; i<array_size; i++){
for(j=0; j<array_size; j++){
array[i][j]=rand()%1000 ;
//printf("%d\t",array[i][j]);
}
//printf("\n");
}
  
for(i=0; i<array_size; i++){
for(j=0; j<array_size; j++){
int min =0, max = 0;
if(i>0 && (array[i][j]>array[i-1][j]))
min =1;
else
max = 1;
if(j>0 && (array[i][j]>array[i][j-1]))
min =1;
else
max = 1;
if(i>0 && j>0 && (array[i][j]>array[i-1][j-1]))
min =1;
else
max = 1;
if(i<array_size-1 && (array[i][j]>array[i+1][j]))
min =1;
else
max = 1;
if(j<array_size-1 && (array[i][j]>array[i][j+1]))
min =1;
else
max = 1;
if(j<array_size-1 && i<array_size-1 && (array[i][j]>array[i+1][j+1]))
min =1;
else
max = 1;
if(j>0 && i<array_size && (array[i][j]>array[i+1][j-1]))
min =1;
else
max = 1;
if(j<array_size && i>0 && (array[i][j]>array[i-1][j+1]))
min =1;
else
max = 1;

if(min==0)
printf("element array[%d][%d] is peak at minimum\n", i, j);
else if(max==0)
printf("element array[%d][%d] is peak at maximum\n", i, j);
}
}


return 0;
}

Add a comment
Know the answer?
Add Answer to:
ugi square Square. 1,000,000 times and see the number Ul ll dimensional board, of type int....
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
  • Write a program that randomly generates a 20 3 20 two-dimensional array, board, of type int....

    Write a program that randomly generates a 20 3 20 two-dimensional array, board, of type int. An element board[i][j] is a peak (either a maximum or a minimum) if all its neighbors (there should be either 3, 5, or 8 neighbors for any cell) are less than board[i][j], or greater than board[i][j]. The program should output all elements in board, with their indices, which are peak. It should also output if a peak is a maximum or a minimum. c++...

  • You are going to write a method (to be called validateBoard) that is going to validate...

    You are going to write a method (to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is possible. Tic- Tac-Toe is played on a 3 x 3 board and players take turns placing either an x or an o on the board. We will assume that in Tic-Tac-Toe the player placing x will go first arld that o will go second. (Learn more about the game here) As the player placing x pieces goes...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • Only part 1, makinf the 2nd and 3rd picture of code do the same thing using...

    Only part 1, makinf the 2nd and 3rd picture of code do the same thing using array Purpose This homework is to learn the concept and usage of one-dimensional (ID) arrays. Part 1 (30 pts) Modify your HW6' (i.e., digit frequency histogram) in a new program (DigitFrequencyArray.java) to use a count array instead of 10 count variables. Your new program should be much shorter than your original code since there is no need for branching statements (if or switch). For...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • java Object Oriented Programming The assignment can be done individually or in teams of two. Submit one as...

    java Object Oriented Programming The assignment can be done individually or in teams of two. Submit one assignment per team of two via Omnivox and NOT MIO.Assignments sent via MIO will be deducted marks. Assignments must be done alone or in groups and collaboration between individuals or groups is strictly forbidden. There will be a in class demo on June 1 make sure you are prepared, a doodle will be created to pick your timeslot. If you submit late, there...

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

  • I need Summary of this Paper i dont need long summary i need What methodology they used , what is the purpose of this p...

    I need Summary of this Paper i dont need long summary i need What methodology they used , what is the purpose of this paper and some conclusions and contributes of this paper. I need this for my Finishing Project so i need this ASAP please ( IN 1-2-3 HOURS PLEASE !!!) Budgetary Policy and Economic Growth Errol D'Souza The share of capital expenditures in government expenditures has been slipping and the tax reforms have not yet improved the income...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

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