Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
6
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int main() {
        int i, j, m, n;
        int isReflexive, isequivalence=1;
        int isSymmetric=1;
        int isTransitive =1;
int mat[100][100];
    printf("Enter the column dimension of the matrix: ");
    scanf("%d", &n);

    for(i = 0; i < n;i++) {
        for(j = 0; j < n;j++) {

                mat[i][j]=rand()%2;
        }
    }
    printf("The randomly generated matrix is : \n");
    for(i = 0; i < n;i++) {
        for(j = 0; j < n;j++) {

               printf("%d  ",mat[i][j]);
        }
        printf("\n");
    }
    //equivalence

    //Reflexive

    for(i = 0; i < n;i++) //o(n)
    if(mat[i][i]==0)
    isReflexive=0;

    //Symmetric

    for(i = 0; i < n;i++) {  //o(n^2)
        for(j = 0; j < n;j++){
            if(mat[i][j]!=mat[j][i])
            isSymmetric=0;
        }
    //Transitive

    for(i = 0; i < n;i++) {   // o(n^3)
        for(j = 0; j < n;j++){
          for( int k=0;k<n;k++){
               if(mat[i][j] && mat[j][k] && !mat[k][i])
               isTransitive=0;
          }
        }
    }

    if(!isReflexive || !isTransitive || !isSymmetric)
    isequivalence=0;

}

        return 0;
}