Помогите пожалуйста доделать задание по С++ с помощью указателей.
Сформировать одномерный массив, состоящий из максимальных значений положительных элементов соответствующих строк произвольно заданной матрицы В. (выполнить с помощью указателей!!!)
Я сделал задачу по обычному (код прикреплю)
у меня получилось сделать по обычному, но не получается с помощью указателей.
помогите пожалуйста.
ТЕКС КОДА:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;
int main()
{
SetConsoleOutputCP (1251);
//ВВод всей инфы
int i;
int z, c; //поиск значений
int x, y, f;
int q;
cout << "ВВедите число элементов для 1-ой строки в массиве B";
cout <<endl;
cin >>x;
cout << "ВВедите число строк в массиве B";
cout <<endl;
cin >>y;
cout << "ВВедите число элементов массиве A";
cout <<endl;
cin >>f;
// :X::Y:
int b[y][x]; // масив B
// :f:
int a[f]; // масив а
int max=10000;
int p_max=10000;
//Заполнение масива
for (int k=0; k<y ;k++){
for (int i=0; i<x ; i++){
cout <<"Введите число в ячейку --["<<k+1<<"]--["<<i+1<<"]--";
cout <<endl;
cin >>b[k][i];
}
}
//Ввывод масива
for (int k=0 ;k<y; k++){
for (int i=0; i<x ; i++){
cout <<b[k][i];
cout <<" ";
}
cout <<endl;
}
//Начало нахождения нужных данных
for (int r=0; r<f ;r++){
q=max;
max=0;
for (int k=0; k<y ;k++){
for (int i=0; i<x ; i++){
if (b[k][i]<p_max and b[k][i]!=q){
if (b[k][i]>max){
max=b[k][i];
c=k;
z=i;
}
}
}
}
cout <<endl;
cout <<r+1<<" макс=" <<max <<" --["<<c+1<<"]-["<<z+1<<"]--" <<endl; //Нахождение 1-ого Макс и вывод
p_max=max;
a[r]=max;
}
// Ввывод готового масива
cout <<endl;
cout <<"Составленный массив А";
cout <<endl;
for (int i=0; i<f ; i++){
cout <<a[i];
cout <<" ";
}
}
#include <iomanip>
#include <iostream>
#include <random>
using namespace std;
int* max_element(int* begin, int* end) {
int* pmax = begin;
while (++begin != end) {
if (*pmax < *begin) {
pmax = begin;
}
}
return pmax;
}
int main() {
uniform_int_distribution<size_t> length(5, 8);
uniform_int_distribution<> value(10, 99);
mt19937 gen{ random_device()() };
auto n = length(gen);
auto m = length(gen);
auto matrix = new int* [n];
const auto row_end = matrix + n;
for (auto row = matrix; row != row_end; ++row) {
*row = new int[m];
auto col_end = *row + m;
for (auto it = *row; it != col_end; ++it) {
*it = value(gen);
cout << setw(4) <<*it;
}
puts("");
}
puts("");
auto vector = new int[n];
auto vec = vector;
const auto vec_end = vector + n;
for (auto row = matrix; row != row_end; ++row, ++vec) {
*vec = *max_element(*row, *row + m);
}
for (auto it = vector; it != vec_end; ++it) {
cout << setw(4) << *it;
}
puts("");
delete[] vector;
for (auto row = matrix; row != row_end; ++row) {
delete[] *row;
}
delete[] matrix;
} "по-обычному" - это с использованием VLA, которые, вообще говоря, в стандартном C++ не существуют? неплохо, неплохо...
а где код, в котором видны хотя бы попытки сделать "через указатели"?