Código
//------------MATRIZ MAGICA------------------------------------------ //*****************************************************************// //*****************************************************************// #include <windows.h> #include <iostream> #include <stdlib.h> //*****************************************************************// //*****************************************************************// using namespace std; //*****************************************************************// //*****************************************************************// int sumarMatrices_filas( int matriz[ 100 ][ 100 ],int filas,int columnas ); int sumarMatrices_columas( int matriz[ 100 ][ 100 ],int filas,int columnas ); void reportar(int A[][100],int fila, int columna); int sumarMatrices_diagonal1( int matriz[ 100 ][ 100 ],int filas,int columnas ); int sumarMatrices_diagonal2( int matriz[ 100 ][ 100 ],int filas,int columnas ); int llenarMatriz( int matriz[ 100 ][ 100 ],int filas,int columnas ); //*****************************************************************// //*****************************************************************// int main() { int matriz_a[ 100 ][ 100 ]; int filas,columnas; float suma1=0,suma2=0,suma3=0,suma4=0,hi; cout << "Ingrese cantidad de filas: " ; cin >> filas; cout << "Ingrese cantidad de columnas: "; cin >> columnas; llenarMatriz( matriz_a,filas,columnas ); cout<<"-----------------------------------------"<<endl; cout<<"-----------------------------------------"<<endl; cout<<"MATRIZ A"<<endl; reportar(matriz_a,filas,columnas); cout<<"-----------------------------------------"<<endl; cout<<"-----------------------------------------"<<endl; suma1=sumarMatrices_filas(matriz_a,filas,columnas ); suma2=sumarMatrices_columas(matriz_a,filas,columnas ); suma3=sumarMatrices_diagonal1(matriz_a,filas,columnas ); suma4=sumarMatrices_diagonal2(matriz_a,filas,columnas ); cout<<"SUMA DE FILAS"<<" "<<suma1<<endl; cout<<"SUMA DE COLUMNAS"<<" "<<suma2<<endl; cout<<"SUMA DE DIAGONAL 1"<<" "<<suma3<<endl; cout<<"SUMA DE DIAGONAL 2"<<" "<<suma4<<endl; cout<<suma1/suma3<<endl; cout<<suma2/suma4<<endl; //hi=suma1/filas; //if(suma1/suma3==suma2/suma4 && hi<= filas) if(suma1/suma3==suma2/suma4) { //cout<<"ES MATRIZ MAGICA"<<endl; cout<<"\a";MessageBox (0," ES MATRIZ MAGICA "," :}",MB_OK|MB_SYSTEMMODAL); } if(suma1/suma3!=suma2/suma4) { //cout<<"NO ES MATRIZ MAGICA"<<endl; cout<<"\a";MessageBox (0," NO ES MATRIZ MAGICA "," :}",MB_OK|MB_SYSTEMMODAL); } cin.ignore(); cin.get(); return 0; } //*****************************************************************// //*****************************************************************// void reportar(int A[][100],int fila, int columna) { int i=0, j=0; for(i=0;i<fila;i++) { for(j=0;j<columna;j++) { cout<<A[i][j]<<"\t"; } cout<<"\n"; } cout<<"\n"; } //*****************************************************************// //*****************************************************************// int llenarMatriz( int matriz[ 100 ][ 100 ],int filas,int columnas ) { int a,b; for( a=0;a<filas;a++ ) for( b=0;b<columnas;b++ ) { // cin>>matriz[ a ][ b ]; matriz[ a ][ b ]=1 + rand() % 100; } } //*****************************************************************// //*****************************************************************// int sumarMatrices_filas( int matriz[ 100 ][ 100 ],int filas,int columnas ) { int a,b,suma=0; for( a=0;a<filas;a++ ) { for( b=0;b<columnas;b++ ) { suma=matriz[ a ][ b ]+suma; } } return suma; } //*****************************************************************// //*****************************************************************// int sumarMatrices_columas( int matriz[ 100 ][ 100 ],int filas,int columnas ) { int a,b,suma=0; for( a=0;a<columnas;a++ ) { for( b=0;b<filas;b++ ) { suma=matriz[ a ][ b ]+suma; } } return suma; } //*****************************************************************// //*****************************************************************// int sumarMatrices_diagonal1( int matriz[ 100 ][ 100 ],int filas,int columnas ) { int a,suma=0; for( a=0;a<columnas;a++ ) { suma=matriz[ a ][ a ]+suma; } return suma; } //*****************************************************************// //*****************************************************************// int sumarMatrices_diagonal2( int matriz[ 100 ][ 100 ],int filas,int columnas ) { int a,suma=0; for( a=0;a<columnas;a++ ) { suma=matriz[ a ][filas-a-1 ]+suma; } return suma; } //*****************************************************************// //*****************************************************************//
a ver si les sirve-...............