ALGORITHM
Warshalls algorithm using dynamic programming in C Programming
#include
#include
#include
#define MAX 7
void fnWarshall(int aiAdj[MAX][MAX],int iN)
{
int iI,iJ,iK;
for(iK=0;iK
{
printf("\nTranstive Closure : %d\n",iK+1);
for(iI=0;iI
{
for(iJ=0;iJ
{
aiAdj[iI][iJ]=(aiAdj[iI][iJ]||(aiAdj[iI][iK] && aiAdj[iK][iJ]));
printf(" %d ",aiAdj[iI][iJ]);
}
printf("\n");
}
}
}
void main()
{
int aiAdj[MAX][MAX],iI,iJ,iN;
clrscr();
printf("Enter the no of Vertices : ");
scanf("%d",&iN);
printf("\nEnter the adjency Matrix \n ");
for(iI=0;iI
for(iJ=0;iJ
scanf("%d",&aiAdj[iI][iJ]);
fnWarshall(aiAdj,iN);
getch();
}
/*
OutPut
Enter the no of Vertices : 4
Enter the adjency Matrix
0 1 0 0
0 0 0 0
0 0 0 1
1 0 0 0
Transtive Closure : 1
0 1 0 0
0 0 0 0
0 0 0 1
1 1 0 0
Transtive Closure : 2
0 1 0 0
0 0 0 0
0 0 0 1
1 1 0 0
Transtive Closure : 3
0 1 0 0
0 0 0 0
0 0 0 1
1 1 0 0
Transtive Closure : 4
0 1 0 0
0 0 0 0
1 1 0 1
1 1 0 0
*/