| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 
 | #include <iostream>
#include <windows.h>
 
 
 
using namespace std;
 
const int TAILLE_MAX = 100;
 
// définition d'une matrice carree d'ordre TAILLE_MAX
typedef int Carre[TAILLE_MAX][TAILLE_MAX];
 
// Fonction sommeLigne
int sommeLigne ( const Carre ok , const int n , const int i)
{
 
    int som=0;
 
    for (int j=0 ; j < n; j++)
  {
   som = som + ok[i][j];
  }
    return som;
}
 
// Fonction sommeColonne
int sommeColonne ( const Carre ok , const int n , const int j)
{
 
    int som=0 ;
 
 
    for ( int i=0;  i< n ; i++ )
      {
         som = som + ok[j][i] ;
      }
     return som ;
}
 
//Fonction somme1èrediagonale
int somme1erediagonale ( const Carre carre, const int n )
  {
     int som=0;
 
 
     for ( int i=0  ; i < n  ; i++   )
       {
          som = som + carre[i][i] ;
       }
     return som;
  }
//Fonction somme 2ème diagonale
 
    int somme2emediagonale(const Carre carre, const int n)
{
     int som=0 ;
     int i,j;
 
 
     for (  i=0  , j=n-1  ; i < n  ; i++ , j--  )
 
       {
          som = som + carre[i][j] ;
       }
 
      return som;
  }
 
bool estCarreMagique ( const Carre ok, const int n )
{
   int som;
   int i,j;
   bool reponse   ;
   som = sommeLigne(ok,n,i);
 
     if (  sommeColonne(ok,n,i) != som )
     {
      reponse = false;
      }
 
     return reponse;
}
 
int main()
{
  int i,j,n,som;
  bool reponse;
 
Carre ok = { {17, 24, 1, 8, 15 },
{23, 5, 7, 14, 16},
{4, 6, 13, 20, 22},
{10, 12, 19, 21, 3},
{11, 18, 25, 2, 9 }};
 
 
 
 
reponse=estCarreMagique(ok,5);
cout << reponse << endl ;
Sleep(10000);
} | 
Partager