Răspuns :
Răspuns:
# include<iostream>
using namespace std;
unsigned modul(int x, int y){
if(y - x < 0)
return (-1)*(y-x);
return (y-x);
}
int main(){
int n, maxim, it, S;
cin>>n;
int a[n][n], b[n], e, itmax, x[n], y[n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin>>a[i][j];
for(int i = 0; i < n; i++)
cin>>b[i];
cin>>e>>itmax;
for(int i = 0; i< n; i++)
cin>>x[i];
it = 0;
do {
maxim = 0;
for(int i = 0; i < n; i++){
S = 0;
for(int j = 0; j < n; j++){
if(j!=i)
S += a[i][j]*x[j];
}
y[i] = (b[i] - S) / a[i][i];
if (maxim < modul(x[i], y[i]))
maxim = modul(x[i], y[i]);
}
for(int i = 0; i < n ; i++){
x[i] = y[i];
}
it += 1;
} while((maxim > e) && (it <= itmax));
if(it > itmax){
cout<<"Nu se poate afisa solutia in "<<itmax<<" iteratii, cu precizia "<<e;
}else{
cout<<"Solutia obtinuta in "<<it<< " iteratii cu precizia "<<e<<" este ";
for(int i = 0; i < n; i++)
cout<<x[i]<<" ";
}
return 0;
}
Daca am omis ceva, lasa un reply. Salut!