Login
Order Now
Support
C++ Programming Solution on Adjacency Matrix Task

C++ Programming Solution on Adjacency Matrix Task

  • 17th Nov, 2022
  • 17:19 PM

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[]){
    
    fstream fin;
    fin.open(argv[1]);
    
    int n, e, u, v, w;
    fin >> n;
    fin >> e;
    
    int AdjMat[n+1][n+1];
    
    for(int i=1; i<n+1; i++){
        for(int j=1; j<n+1; j++){
            AdjMat[i][j] = 0;
        }
    }
    
    for(int i=0; i<e; i++){
        fin >> u >> v >> w;
        AdjMat[u][v] = w;
        AdjMat[v][u] = w;
    }
    
    // Display
    
    for(int i=1; i<n+1; i++){
        for(int j=1; j<n+1; j++){
            cout << AdjMat[i][j] << " ";
        }
        cout << endl;
    }
    
    fin.close();
    
    return 0;
}
 

Share this post

assignment helpassignment helperassignment expertsassignment writing services