#include #include main(int argc, char *argv[]) { //definition of the variables. float mtx1[20][20], mtx2[20][20], mtx3[20][20]; float min; int n, i, j, k; //exit if the number of arguments is not 2. if(argc != 3) { cerr << "Usage: vm \n"; return 1; } //open the input file 1. exit if an error occurs. ifstream fin1(argv[1]); if(!fin1) { cerr << "Can't open file1!\n"; return 1; } //read the input file 1. fin1 >> n; //read the number of rows and columns. for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { fin1 >> mtx1[i][j]; //read the elements of the matrix. } } fin1.close(); //close the file 1. //open the input file 2. exit if an error occurs. ifstream fin2(argv[2]); if(!fin2) { cerr << "Can't open file2!\n"; return 1; } fin2 >> n; //read the number of rows and columns. for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { fin2 >> mtx2[i][j]; ///read the elements of the matrix. } } fin2.close(); //close the file 2. for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { min = 9999; for(k=1; k<=n; k++) { if(min > mtx2[i][k] + mtx1[k][j]) { min = mtx2[i][k] + mtx1[k][j]; //find the shortest path. } } mtx3[i][j] = min; //put distance of the shortest path. } } //output of the result. cout << n << "\n"; for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { cout << mtx3[i][j]; if(i < n) { cout << "\t"; } } cout << "\n"; } return 0; } //end of the program.