Відповідь:
C++ code:
#include <iostream>
#include <cstdlib>
#include <ctime>
void randarr(int **arr,const int n,const int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i][j] = rand() % 30 - 10;
}
void printarr(int **arr,const int n,const int m){
std::cout << arr[i][j] << "\t";
std::cout << std::endl;
int MIN(int **arr,const int n,const int m){
int min = arr[0][0];
if(arr[i][j] < min){
min = arr[i][j];
return min;
void average(int **arr,const int n,const int m){
double average = 0,counter = 0;
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(arr[j][i] % 2 != 0){
average += arr[j][i];
counter++;
if(counter != 0){
average /= counter;
std::cout << i << " Cols = " << average << std::endl;
average = 0;
counter = 0;
int main(){
srand(time(NULL));
const int n = 3,m = 4;
int **arr = new int*[n];
arr[i] = new int[m];
randarr(arr,n,m);
printarr(arr,n,m);
average(arr,n,m);
delete[] arr[i];
delete[] arr;
return 0;
Пояснення:
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Відповідь:
C++ code:
#include <iostream>
#include <cstdlib>
#include <ctime>
void randarr(int **arr,const int n,const int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i][j] = rand() % 30 - 10;
}
}
}
void printarr(int **arr,const int n,const int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
std::cout << arr[i][j] << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
int MIN(int **arr,const int n,const int m){
int min = arr[0][0];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(arr[i][j] < min){
min = arr[i][j];
}
}
}
return min;
}
void average(int **arr,const int n,const int m){
double average = 0,counter = 0;
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(arr[j][i] % 2 != 0){
average += arr[j][i];
counter++;
}
}
if(counter != 0){
average /= counter;
}
std::cout << i << " Cols = " << average << std::endl;
average = 0;
counter = 0;
}
}
int main(){
srand(time(NULL));
const int n = 3,m = 4;
int **arr = new int*[n];
for(int i = 0; i < n; i++){
arr[i] = new int[m];
}
randarr(arr,n,m);
printarr(arr,n,m);
average(arr,n,m);
for(int i = 0; i < n; i++){
delete[] arr[i];
}
delete[] arr;
return 0;
}
Пояснення: