Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Floyd Warshall (all pair shortest path )

Source Code:   


#include<iostream.h>
#include<conio.h>


void main()
{clrscr();
int g[10][10],n,i,j,k;
cout<<"program for Floyd warshall (all pair shortest path)by: Tarun rawat\n\n";


cout<<"Enter number of vertices n= ";
cin>>n;
cout<<"Enter n*n adjacency matrix \n";
for(i=0;i<n;i++)
  {for(j=0;j<n;j++)
      { cin>>g[i][j];
      }
  }
for(k=0;k<n;k++)
  {for(i=0;i<n;i++)
      {
       if (g[i][k]>0)
      {for(j=0;j<n;j++)
     {if(g[k][j]>0 && g[i][j]>(g[i][k]+g[k][j]))
       {g[i][j]=g[i][k]+g[k][j];
       }
     }
      }
      }
  }
cout<<"\nOutput : \n";
for(i=0;i<n;i++)
  {for(j=0;j<n;j++)
      { cout<<g[i][j]<<" ";
      }
     cout<<"\n";
  }

getch();
}

4 comments:


  1. nice article for beginners.thank you.
    javacodegeeks
    welookups

    ReplyDelete
  2. Thanks for sharing nice information about C++ . Keep Sharing..

    ReplyDelete
  3. Cool and that i have a neat supply: What Renovations Can You Claim On Tax house renovation ideas interior

    ReplyDelete

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)