как решается эта задачка на C++?
Составить функцию определения наибольшего элемента каждой строки матрицы f[n][m]. Используя эту функцию определить наибольшее значение суммы элементов каждой строки в матрицах G[4][4], T[6][6]
А что именно у вас вызывает трудности? Какие-нибудь наработки уже есть? Или пока на уровне - "даже не знаю как подступиться"?
Код:
#include<iostream>
#include<ctime>
int **CreateArray(unsigned int size, int range_min, int range_max);
int RangedRandDemo( int range_min, int range_max );
void PrintArray(int **Arr, unsigned int size);
int TheBigestNumSumInRows(int **Arr, unsigned int size);
void WhoIsTheBiggest(int big_matrix_G, int big_matrix_T);
void FreeMemory(int **Arr, unsigned int size);
int main()
{
srand((unsigned int )time(NULL));
unsigned int size_matrix_G = 4, size_matrix_T = 6;
int **matrix_G = CreateArray(size_matrix_G,0,9);
int **matrix_T = CreateArray(size_matrix_T,0,9);
PrintArray(matrix_G, size_matrix_G);
int big_matrix_G = TheBigestNumSumInRows(matrix_G, size_matrix_G);
PrintArray(matrix_T, size_matrix_T);
int big_matrix_T = TheBigestNumSumInRows(matrix_T, size_matrix_T);
WhoIsTheBiggest(big_matrix_G, big_matrix_T);
FreeMemory(matrix_G,size_matrix_G);
FreeMemory(matrix_T,size_matrix_T);
std::cout<<std::endl;
system("pause");
return 0;
}
int **CreateArray(unsigned int size, int range_min, int range_max)
{
int **Arr = new int*[size];
for(unsigned int idx=0; idx<size;idx++)
Arr[idx] = new int[size];
for(unsigned int idx=0; idx<size;idx++)
for(unsigned int jdx=0; jdx<size;jdx++)
Arr[idx][jdx] = RangedRandDemo(range_min,range_max);
return Arr;
}
int RangedRandDemo( int range_min, int range_max)
{
int u = (double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;
return u;
}
void PrintArray(int **Arr, unsigned int size)
{
std::cout<<"Array size: "<<size<<std::endl;
for(unsigned int idx=0;idx<size;idx++)
{
for(unsigned int jdx=0;jdx<size;jdx++)
{
std::cout<<Arr[idx][jdx]<<"\t";
}
std::cout<<std::endl;
}
}
int TheBigestNumSumInRows(int **Arr, unsigned int size)
{
std::cout<<std::endl;
int summa = 0;
for(unsigned int idx=0; idx<size; idx++)
{
int BigNum = 0;
for(unsigned int jdx=0;jdx<size;jdx++)
{
if(Arr[idx][jdx]>BigNum)
{
BigNum = Arr[idx][jdx];
}
}
std::cout<<BigNum<<" ";
summa += BigNum;
}
std::cout<<"\nSumma = "<<summa<<std::endl;
return summa;
}
void WhoIsTheBiggest(int big_matrix_G, int big_matrix_T)
{
if(big_matrix_G > big_matrix_T)
{
std::cout<<"matrix_G summa is the biggest: "<<big_matrix_G<<std::endl;
}
if(big_matrix_G < big_matrix_T)
{
std::cout<<"matrix_T summa is the biggest: "<<big_matrix_T<<std::endl;
}
if(big_matrix_G == big_matrix_T)
{
std::cout<<"matrix_G summa and matrix_G summa are equal: "<<big_matrix_G<<"=="<<big_matrix_T<<std::endl;
}
}
void FreeMemory(int **Arr, unsigned int size)
{
for(unsigned int idx=0; idx<size; idx++)
{
delete Arr[idx];
}
delete []Arr;
}
#include<ctime>
int **CreateArray(unsigned int size, int range_min, int range_max);
int RangedRandDemo( int range_min, int range_max );
void PrintArray(int **Arr, unsigned int size);
int TheBigestNumSumInRows(int **Arr, unsigned int size);
void WhoIsTheBiggest(int big_matrix_G, int big_matrix_T);
void FreeMemory(int **Arr, unsigned int size);
int main()
{
srand((unsigned int )time(NULL));
unsigned int size_matrix_G = 4, size_matrix_T = 6;
int **matrix_G = CreateArray(size_matrix_G,0,9);
int **matrix_T = CreateArray(size_matrix_T,0,9);
PrintArray(matrix_G, size_matrix_G);
int big_matrix_G = TheBigestNumSumInRows(matrix_G, size_matrix_G);
PrintArray(matrix_T, size_matrix_T);
int big_matrix_T = TheBigestNumSumInRows(matrix_T, size_matrix_T);
WhoIsTheBiggest(big_matrix_G, big_matrix_T);
FreeMemory(matrix_G,size_matrix_G);
FreeMemory(matrix_T,size_matrix_T);
std::cout<<std::endl;
system("pause");
return 0;
}
int **CreateArray(unsigned int size, int range_min, int range_max)
{
int **Arr = new int*[size];
for(unsigned int idx=0; idx<size;idx++)
Arr[idx] = new int[size];
for(unsigned int idx=0; idx<size;idx++)
for(unsigned int jdx=0; jdx<size;jdx++)
Arr[idx][jdx] = RangedRandDemo(range_min,range_max);
return Arr;
}
int RangedRandDemo( int range_min, int range_max)
{
int u = (double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;
return u;
}
void PrintArray(int **Arr, unsigned int size)
{
std::cout<<"Array size: "<<size<<std::endl;
for(unsigned int idx=0;idx<size;idx++)
{
for(unsigned int jdx=0;jdx<size;jdx++)
{
std::cout<<Arr[idx][jdx]<<"\t";
}
std::cout<<std::endl;
}
}
int TheBigestNumSumInRows(int **Arr, unsigned int size)
{
std::cout<<std::endl;
int summa = 0;
for(unsigned int idx=0; idx<size; idx++)
{
int BigNum = 0;
for(unsigned int jdx=0;jdx<size;jdx++)
{
if(Arr[idx][jdx]>BigNum)
{
BigNum = Arr[idx][jdx];
}
}
std::cout<<BigNum<<" ";
summa += BigNum;
}
std::cout<<"\nSumma = "<<summa<<std::endl;
return summa;
}
void WhoIsTheBiggest(int big_matrix_G, int big_matrix_T)
{
if(big_matrix_G > big_matrix_T)
{
std::cout<<"matrix_G summa is the biggest: "<<big_matrix_G<<std::endl;
}
if(big_matrix_G < big_matrix_T)
{
std::cout<<"matrix_T summa is the biggest: "<<big_matrix_T<<std::endl;
}
if(big_matrix_G == big_matrix_T)
{
std::cout<<"matrix_G summa and matrix_G summa are equal: "<<big_matrix_G<<"=="<<big_matrix_T<<std::endl;
}
}
void FreeMemory(int **Arr, unsigned int size)
{
for(unsigned int idx=0; idx<size; idx++)
{
delete Arr[idx];
}
delete []Arr;
}
Что за бредовое условие? С помощью функции, выдающей максимальное значение одного элемента из строки посчитать сумму всех элементов строки???