Cześć mam problem z tym kodem:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int wspolrzedne(int a, int b)
{
if((cin >> a) && (a <= b && a > 0))
return a;
else{
cin.clear();
cin.sync();
cout << "Blad, podaj jeszcze raz" << endl;
wspolrzedne(a, b);
}
}
int main()
{
int sumay = 0, sumax = 0, sumacala = 0;
srand(time(NULL));
int m = (rand() % 10) + 1;
int n = (rand() % 10) + 1;
int x = 5, y = 5;
cout << "Podaj wspolrzedna punktu x " << "mniejsza rowna " << m << endl;
wspolrzedne(x, m);
cout << "Podaj wspolrzedna punktu y: " << "mniejsza rowna " << n << endl;
wspolrzedne(y, n);
int tab[m][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
tab[j][i] = (rand() % 9 + 1);
}
}
for(int i = 0; i < m; ++i){
sumay += tab[i][y];
}
for(int i = 0; i < n; ++i){
sumax += tab[x][i];
}
sumacala = sumax + sumay - tab[x][y];
cout << sumacala << endl;
for(int i = 0; i < n; i++){
cout << endl;
for(int j = 0; j < m; j++){
cout << tab[j][i] << " ";
}
}
}
Kiedy zmieniam wielkości macierzy to wyrzuca mi złe wyniki, nie mogę sobie poradzić z tym zadaniem. Proszę o pomoc.