Subscribe Us

Responsive Advertisement

Advertisement

problem37(path matrix of warshall algorith)

 

problem37(path matrix of warshall algorith)



#include<stdio.h>

int adj[100][100];

void display(int matrix[100][100],int nodes)

{

    for(int i=0;i<nodes;i++)

    {

        for(int j=0;j<nodes;j++)

        {

            printf("%d ",matrix[i][j]);

        }

        printf("\n");

    }


}

int main()

{

    int node ,edge;

    printf("Enter number of nodes : ");

    scanf("%d",&node);

    printf("Enter number of edges : ");

    scanf("%d",&edge);

    while(edge--)

    {

        int u,v;

       printf("Enter number of path: ");

       scanf("%d%d",&u,&v);

       adj[u][v]=1;


    }

    display(adj,node);

    printf("\n");

    for(int k=0;k<node;k++)

    {

         for(int i=0;i<node;i++)

         {

              for(int j=0;j<node;j++)

                {

                 adj[i][j]=adj[i][j]||(adj[i][k]&&adj[k][j]);


                  }


          }

          display(adj,node);

          printf("\n");


    }


}


Post a Comment

0 Comments