zoukankan      html  css  js  c++  java
  • warshall、

     1 #include<iostream>
     2 int mian()
     3 {
     4     int a[4][3],b[3][4],c[4][4];
     5     int i,j,k;
     6     cout<<"input the Boolean Product of A:"<<endl;
     7     for(i=0;i<4;i++)
     8         for(j=0;j<3;j++)
     9             cin>>a[i][j];
    10 
    11     cout<<"input the Boolean Product of A:"<<endl;
    12     for(i=0;i<3;i++)
    13         for(j=0;j<4;j++)
    14             cin>>b[i][j];
    15     for(i=0;i<4;i++)
    16         for(j=0;j<4;j++)
    17             for(k=0;k<3;k++)
    18             {
    19                 if(a[i][k]*b[k][j]==1)
    20                     c[i][j]=1;
    21                 else
    22                     c[i][j]=0;
    23             }
    24     cout<<"The Boolean Product of A and B is:
    "<<endl;
    25     for(i=0;i<4;i++)
    26     {
    27         cout<<endl;
    28         for(j=0;j<4;j++)
    29             cout<<c[i][j];
    30     }
    31     cout<<end;
    32 }
     1 #include<iostream>
     2 using namespace std;
     3 void sMatrix(int **arr,int n);
     4 void rMatrix(int **arr,int n);
     5 void tMatrix(int **arr,int n);
     6 void outPut(int *arr,int n);
     7 
     8 int main()
     9 {
    10     int n,p;
    11     cout << "Please input n:" << endl;
    12     cin >> n;
    13     int *arr = new int[n];
    14     int **arr1 = new int*[n];
    15 
    16     for (int i = 0; i < n; i++)
    17         arr1[i] = new int[n];
    18 
    19     cout << "Please input numbers:" << endl;
    20     for (int i = 0; i < n; i++)
    21         cin >> arr[i];
    22     
    23     for (int i = 0; i < n; i++)
    24         for (int j = 0; j < n; j++)
    25         {
    26             if (arr[i] % arr[j] == 0)
    27                 arr1[i][j] = 1;
    28             else
    29                 arr1[i][j] = 0;
    30         }
    31     cout << "Please input p:1,对称关系的判断;2,自反关系的判断;3,传递关系的判断" << endl;
    32     cin >> p;
    33     switch (p)
    34     {
    35     case 1:sMatrix(arr1,n); break;
    36     case 2:rMatrix(arr1,n); break;
    37     case 3:tMatrix(arr1,n); break;
    38     default:exit(0);
    39 
    40     }
    41 }
    42 
    43 
    44 void sMatrix(int **arr1,int n)
    45 {
    46     int c=1,d=1;
    47     for (int i = 0; i < n; i++)
    48         for (int j = 0; j < n; j++)
    49             if (arr1[i][j] == arr1[j][i])
    50                 c = 0;
    51             else
    52                 d = 0;
    53     if (c == 0 && d == 0)
    54         cout << "该矩阵既是对称又是反对称!" << endl;
    55     else 
    56         if (c == 0)
    57         cout << "该矩阵对称!" << endl;
    58     else
    59         if (d == 0)
    60         cout << "该矩阵反对称!" << endl;    
    61 }
    62 
    63 void rMatrix(int **arr1, int n)
    64 {
    65     int c;
    66     for (int i = 0; i < n; i++)
    67         if (arr1[i][i] = 1)
    68         {
    69             c = 1;
    70             break;
    71         }
    72         if (c == 1)
    73             cout<<"该矩阵是自反的!"<<endl;
    74         else 
    75             cout<<"该矩阵是反自反的!"<<endl;
    76 
    77 }
    78 
    79 void tMatrix(int **arr1,int n)
    80 {
    81     int c = 1;
    82     for (int i = 0; i < n; i++)
    83         for (int j = 0; j < n; j++)
    84             for (int k = 0; k < n; k++)
    85             {
    86                 if (arr1[i][j] == arr1[j][k] == arr1[i][j])
    87                 {
    88                     c = 0;
    89                     break;
    90                 }
    91 
    92             }
    93             if (c == 0)
    94                 cout << "该矩阵是传递的!" << endl;
    95             else
    96                 cout << "该矩阵是非传递的" << endl;
    97 
    98 }
  • 相关阅读:
    问题2017S03
    问题2017S02
    高等代数问题1
    无穷积分换元法的严格解释
    线性空间的同构理论
    问题2017S01
    朴素贝叶斯分类
    决策树
    温习MATLAB
    感知机
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3384852.html
Copyright © 2011-2022 走看看