0% found this document useful (0 votes)
2 views

ADA_program3

The document contains two C/C++ programs: one for solving the All-Pairs Shortest Paths problem using Floyd's algorithm and another for finding the transitive closure using Warshall's algorithm. Each program prompts the user for the number of vertices and the graph data, then computes and displays the resulting matrices. Both algorithms utilize nested loops to update the matrices based on their respective logic.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ADA_program3

The document contains two C/C++ programs: one for solving the All-Pairs Shortest Paths problem using Floyd's algorithm and another for finding the transitive closure using Warshall's algorithm. Each program prompts the user for the number of vertices and the graph data, then computes and displays the resulting matrices. Both algorithms utilize nested loops to update the matrices based on their respective logic.
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 3

A) Design and implement C/C++ Program to solve All-Pairs Shortest Paths problem using
Floyd'salgorithm

#include<stdio.h>

#include<conio.h>

#define INF 999

int min(int a,int b)

return(a<b)?a:b;

void floyd(int p[][10],int n)

int i,j,k;

for(k=1;k<=n;k++)

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

p[i][j]=min(p[i][j],p[i][k]+p[k][j]);

void main()

int a[10][10],n,i,j;

clrscr();

printf("\nEnter the n value:");

scanf("%d",&n);
printf("\nEnter the graph data:\n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

scanf("%d",&a[i][j]);

floyd(a,n);printf("\nShortest path matrix\n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

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

printf("\n");

getch();

B) Design and implement C/C++ Program to find the transitive closure using
Warshal'salgorithm.

#include<stdio.h>

void warsh(int p[][10],int n)

int i,j,k;

for(k=1;k<=n;k++)

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

p[i][j]=p[i][j] || p[i][k] && p[k][j];


}

int main()

int a[10][10],n,i,j;

printf("\nEnter the n value:");

scanf("%d",&n);

printf("\nEnter the graph data:\n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

scanf("%d",&a[i][j]);

warsh(a,n);

printf("\nResultant path matrix\n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

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

printf("\n");

return 0;

You might also like