A
A
Archpriest Metapop2020-08-14 18:44:31
C++ / C#
Archpriest Metapop, 2020-08-14 18:44:31

The symmetry of the array about the main diagonal. What's wrong?

Array arr[i][j] with real numbers.
a and b are dimensions.

//проверяем симметрию//
                                       
cout << "\n";                                                 
//переменная-показатель симметрии//                           
sim= true;                                                    
//прогоняем массив//                                          
for (int i = 0; i < a; i++)                                   
{                                                             
    for (int j = 0; j < b;j++)                                
    {                                                         
        //если зеркальные значения не равны sim становится ложным //
        if (i=j) break;
        if (arr[i][j] != arr[j][i])                           
            {                                                 
            sim = false;                                      
            break;                                            
            }                                                 
    if (sim=false) break;                                     
    }                                                         
}      
//выводим ответ//                                                       
if (sim=true)                                                 
    cout<<"Массив симметричен"<<endl;                         
if (sim=false)                                                
    cout<<"Массив несимметричен"<<endl;


Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2020-08-14
@caramel14

What's wrong:
1. The if(a=b) expression must be replaced with if(a==b)
2. Real numbers a and b are equal if fabs(a - b) < EPSILON. Therefore, the expression if(a!=b) must be replaced with if(!(fabs(a - b) < EPSILON))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question