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.
`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.
Get Answers For Free
Most questions answered within 1 hours.