Question

Write a C++ Function that finds the 4 values that are adjacent of one another (Vertical,...

Write a C++ Function that finds the 4 values that are adjacent of one another (Vertical, Diagonal, or Horizontal) in a 15x15 2-D Array that sums up to the largest value in the entire array and that returns/ prints out those 4 values and their sum.

Homework Answers

Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

#include <iostream>
#include<cstdlib>
using namespace std;
void find4values(int a[15][15])
{
int l=a[0][0];
for(int i=0;i<15;i++)
{
for(int j=0;j<15;j++)
{
if(l<a[i][j])
l=a[i][j];
}
}
for(int i=0;i<14;i++)
{
for(int j=0;j<14;j++)
{
if(a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1]==l)
{
cout<<"The 4 values are: "<<a[i][j]<<", "<<a[i+1][j]<<", "<<a[i][j+1]<<", "<<a[i+1][j+1]<<"\n";
cout<<"The sum is "<<l<<endl;
}
}
}
}
void printArray(int a[15][15])
{
for(int i=0;i<15;i++)
{
for(int j=0;j<15;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int a[15][15]={{12, 17, 12, 16, 15, 17, 12, 17, 10, 10, 19, 16, 14, 10, 19},{10, 7, 11, 19, 13, 16, 13, 12, 16, 11, 9, 18, 7, 17, 11},{20, 11, 12, 11, 7, 6, 13, 13, 14, 10, 16, 14, 13, 10, 5},{15, 9, 8, 11, 8, 8, 10, 20, 13, 17, 8, 19, 8, 9, 9},{18, 19, 18, 16, 18, 15, 11, 19, 11, 19, 12, 11, 12, 10, 5},{20, 12, 11, 18, 16, 12, 11, 10, 13, 12, 17, 10, 19, 10, 10},{9, 17, 6, 15, 14, 15, 20, 18, 9, 5, 19, 19, 11, 13, 11},{8, 14, 11, 11, 18, 19, 11, 14, 17, 6, 8, 12, 5, 19, 5},{20, 15, 13, 5, 6, 5, 9, 15, 8, 20, 17, 15, 5, 14, 14},{10, 16, 10, 8, 11, 17, 11, 13, 19, 8, 12, 16, 13, 19, 8},{12, 5, 14, 12, 20, 17, 12, 14, 9, 8, 15, 13, 7, 12, 20},{12, 15, 20, 15, 5, 8, 10, 5, 17, 15, 10, 14, 20, 18, 11},{20, 18, 19, 15, 13, 9, 17, 7, 9, 17, 14, 12, 6, 17, 10},{1, 0, 20, 16, 20, 13, 5, 8, 15, 14, 5, 15, 19, 18, 17},{19, 0, 8, 9, 11, 19, 8, 17, 12, 18, 5, 5, 13, 9, 11}};
cout<<"The 2-D ARRAY IS\n\n";
printArray(a);
cout<<"\nThe results are\n\n";
find4values(a);
return 0;

}

Kindly revert for any queries

Thanks.

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
(C++) Write a function that takes an input parameter an int and returns nothing. It then...
(C++) Write a function that takes an input parameter an int and returns nothing. It then generates an array of random numbers the length of the int parameter. It fills the array with random numbers between 0 and 50. It then prints out the array. Without creating a new array, the function then reverses the array and prints out the reversed array. So if the first array was: 22,10,8,5,3,18 The reversed array would be: 18,3,5,8,10,22 Note: the numbers in the...
Write a C++ program that reads data from a file, stores data in a one-dimensional array,...
Write a C++ program that reads data from a file, stores data in a one-dimensional array, and processes data as required. 1) Create a text file named “hw2data.txt” that contains student test scores in the range of 0~100. You can use the following sample data: 76.5 84 75 62 94.5 75.7 93 54 36.5 87.3 81.5 89.5 68 90 79.5 80 92.5 84 96 100 67.7 78 84.5 47 100 87.5 76.25 87 82.5 64 2) Read test scores from...
C Programming: Write a function that takes in an array of integers and an integer containing...
C Programming: Write a function that takes in an array of integers and an integer containing the count of elements, then have it returns the sum of all the even values inside the array.
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
C programing Write a function that takes an array of integers and applies another function (f(x)=...
C programing Write a function that takes an array of integers and applies another function (f(x)= 3x+4) on each element and then stores the result in another array and finally return it once it is done.
Write a template function maxn() that takes as its arguments an array of items of type...
Write a template function maxn() that takes as its arguments an array of items of type T and an integer representing the number of elements in the array and that returns the largest item in the array. The number of elements should take the default value of 10. The program should include a specialization that takes an array of strings as an argument and returns the longest string. (If there is a tie, the function should return the first one...
1) Write a function in C that takes in a single integer parameter and returns an...
1) Write a function in C that takes in a single integer parameter and returns an array of factors. The function signature should be : int* get_factors(int number) To make things a little easier, assume that the input (number) will never have more than 100 factors. The returned array should be null-terminated. 2) Write a main() function that asks a user for a number, calls the function above, then prints the results.
Your assignment is to write a c++ function that can calculate values for any 5 th...
Your assignment is to write a c++ function that can calculate values for any 5 th order polynomial function. ?(?) = ?0 + ?1? + ?2? 2+?3? 3 + ?4? 5 + ?5? 5 Your function should accept only two parameters, the first parameter should be the value of x at which to calculate y(x). The second parameter should be an array with 6 elements that contain the coefficients a0 to a5. The output of your function should be the...
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the...
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the same of values in an array. To test this function in the main, create the following array: int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; #15. Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.
USE C++ Write a sum() function that is used to find the sum of the array...
USE C++ Write a sum() function that is used to find the sum of the array through pointers. In this program we make use of * operator. The * (asterisk) operator denotes the value of variable. Input: array = 2, 4, -6, 5, 8, -1 Output: sum = 12
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT