实验条件:
实验内容及要求:
实验源码:
// allpointpath.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int g[5][5]={{0,3,8,100,-4},
{100,0,100,1,7},
{100,4,0,100,100},
{2,100,-5,0,100},
{100,100,100,6,0},
};
int gg[5][5]={{0,3,8,100,-4},
{100,0,100,1,7},
{100,4,0,100,100},
{2,100,-5,0,100},
{100,100,100,6,0},
};
void show(int a[][5])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("%7d",a[i][j]);
}
printf("\n");
}
printf("\n");
printf("\n");
}
int main(int argc, char* argv[])
{
//i、j标记所以元素
//k标记计算每一个元素时的次数循环
//t记录最小值,以100为无穷大
int i=0,j=0,k=0,t=0;
int count=0;
show(g);
while(count<3)
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
t=g[i][0]+gg[0][j];
for(k=0;k<5;k++)
{
if(t>g[i][k]+gg[k][j])
t=g[i][k]+gg[k][j];
}
if(t>100)
t=100;
gg[i][j]=t;
}
}
show(gg);
count++;
}
getchar();
return 0;
}
实验结果: