bracco&poker
06-02-2014, 07:50
salve, stavo facendo un programma per esercitarmi che mi dava il massimo valore di una matrice, ma ho notato che se usavo le parentesi graffe non mi restituiva un valore corretto, mentre se toglievo le parentesi graffe dopo il for andava tutto bene.
quindi vorrei capire bene quando usare le parentesi graffe per il for.
grazie
ora vi posto i due esempi void max_vet () {
int max = mat [0][0];
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
if(mat[i][j]>max)
max=mat[i][j];
cout<<"Il massimo e"<<max<<endl;
}
}
}
----QUELLO CHE MI DA IL VALORE CORRETTO (SENZA PARENTESI GRAFFE)----
void max_vet () {
int max = mat [0][0];
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
if(mat[i][j]>max)
max=mat[i][j];
cout<<"\nIl massimo e\t"<<max<<endl;
}
quindi vorrei capire bene quando usare le parentesi graffe per il for.
grazie
ora vi posto i due esempi void max_vet () {
int max = mat [0][0];
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
if(mat[i][j]>max)
max=mat[i][j];
cout<<"Il massimo e"<<max<<endl;
}
}
}
----QUELLO CHE MI DA IL VALORE CORRETTO (SENZA PARENTESI GRAFFE)----
void max_vet () {
int max = mat [0][0];
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
if(mat[i][j]>max)
max=mat[i][j];
cout<<"\nIl massimo e\t"<<max<<endl;
}