Niloy007

Shohan's Prob

Apr 25th, 2021
672
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. int main() {
  3.     int node_number, edge_number, a, b;
  4.     printf("Graph Input\n");
  5.     printf("How many node in your graph?\n");
  6.     scanf("%d", &node_number);
  7.  
  8.     int matrix[node_number][node_number];
  9.  
  10.     for (int i = 0; i < node_number; i++) {
  11.         for (int j = 0; j < node_number; j++) {
  12.             matrix[i][j] = 0;
  13.         }
  14.     }
  15.  
  16.     printf("How many edge in your graph?\n");
  17.     scanf("%d", &edge_number);
  18.     printf("Enter %d edge...[Example: 0 {starting_node} 1 {ending_node}]:\n", edge_number);
  19.     for (int i = 0; i < edge_number; i++) {
  20.         scanf("%d %d", &a, &b);
  21.         matrix[a][b] = 1;
  22.         matrix[b][a] = 1;
  23.     }
  24.  
  25.     printf("Here is your graph as adjacency matrix ...\n\n");
  26.     for (int i = 0; i < node_number; i++) {
  27.         printf("|");
  28.         for (int j = 0; j < node_number; j++) {
  29.             printf("%d ", matrix[i][j]);
  30.         }
  31.         printf("| \n");
  32.     }
  33.     return 0;
  34. }
  35.  
RAW Paste Data