Skip to content

Instantly share code, notes, and snippets.

@praserocking
Last active December 15, 2015 16:59
Show Gist options
  • Save praserocking/5293309 to your computer and use it in GitHub Desktop.
Save praserocking/5293309 to your computer and use it in GitHub Desktop.
#include<iostream>
#define min(a,b) (a>b)?b:a;
using namespace std;
int main()
{
int a[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
cout<<"Enter Distance from "<<i+1<<" to "<<j+1<<":";
cin>>a[i][j];
}
for(int k=0;k<3;k++)
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
cout<<"--------------------------------------------------------"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"Minimum Distance From "<<i+1<<" to "<<j+1<<":";
cout<<a[i][j]<<endl;
}
cout<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment