all pair shortest path usking floy warshal
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#define INF 99999
#define MAX 10


void floydWarshall(int graph[MAX][MAX], int n)
{
    int dist[MAX][MAX], i, j, k;


    // Copy initial graph to distance matrix
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            dist[i][j] = graph[i][j];


    // Floyd-Warshall Algorithm
    for (k = 0; k < n; k++)
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                if (dist[i][k] + dist[k][j] < dist[i][j])
                    dist[i][j] = dist[i][k] + dist[k][j];


    // Print result
    printf("\nAll-Pairs Shortest Path Matrix:\n");
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (dist[i][j] == INF)
                printf("INF ");
            else
                printf("%3d ", dist[i][j]);
        }
        printf("\n");
    }
}


int main()
{
    int n, i, j, graph[MAX][MAX];
    char input[10];


    printf("Enter number of vertices: ");
    scanf("%d", &n);


    printf("Enter the adjacency matrix (use INF for infinity):\n");
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%s", input);
            if (strcmp(input, "INF") == 0)
                graph[i][j] = INF;
            else
                graph[i][j] = atoi(input);
        }
    }


    floydWarshall(graph, n);
    return 0;
}
