Friday, October 2, 2009

ADA 5th sem lab prgms

Prgm no 5b
#include
#include
#include
int size, array[5][5],p,q,r;
void algorithm()
{
for(r=1;r<=size;++r)
for(p=1;p<=size;++p)
for(q=1;q<=size;++q)
if((array[p][r]+array[r][q]) < array[p][q])
array[p][q]=array[p][r]+array[r][q];
}
void main()
{
printf("enter the size of graph");
scanf("%d",&size);
printf("enter graph data");
for(p=1;p<=size;++p)
for(q=1;q<=size;++q)
{
scanf("%d",&array[p][q]);
if(array[p][q]==0)array[p][q]=999;
}
algorithm();
printf("shortest path");
for(p=1;p<=size;++p)
{
for(q=1;q<=size;++q)
printf("/t %d",array[p][q]);
printf("/n");
}
}

1 comment: