Jumat, 21 Desember 2012

MATRIX DIAGONAL DENGAN C++



 PROGRAM MENGECEK MATRIX DIAGONAL

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int q;
    int matrix ['q']['q'];
    int x,y;
    int tampung=0,tampung1=0,tampung2=0;
   
    cout<<"masukkan ordo matrix ";
    cin>>q;
    cout<<"matrix["<<q<<"]["<<q<<"]\n";
   
    cout<<"\n";
    for(x=0;x<q;x++){  
         for(y=0;y<q;y++){ 
                     cout<<"masukkan nilai matrix "<<x <<" "<<y<<" :"  ;
                     cin>>matrix[x][y];
                     }
         }
         
    cout<<"=============================================\n";
    for(x=0;x<q;x++){  
         for(y=0;y<q;y++){ 
                     cout<<matrix[x][y];
                    
                     }
                     cout<<endl;
         }
        
        
    for(x=0;x<q;x++){  
         for(y=0;y<q;y++){ 
                     if(x==y && matrix[x][y]==1){
                             tampung=tampung+1;
                            
                             }
                     if(x!=y && matrix[x][y]==0){
                             tampung1=tampung1+1;}
                          
                             }
                     }
        
    if(tampung==q && tampung1==(q*q)-q){
                  cout<<"Matrix diagonal \n";
                  }else{
                  cout<<"bukan matrix diagonal\n";
                  }
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

0 komentar:

Posting Komentar