rana1704

Graph_Random & Num Edges

Oct 5th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int num_of_nodes;
  5.     printf("Enter the Number of NODE: " );
  6.     scanf("%d",&num_of_nodes);
  7.     int i,j,graph[50][50],temp[50][50];
  8.     int number_of_edges=0;
  9.  
  10.  
  11.     for(i=0;i<num_of_nodes;i++)
  12.     {
  13.         for(j=0;j<num_of_nodes;j++)
  14.         {
  15.             if(i!=j)
  16.             {
  17.                 graph[i][j]=rand()%2;
  18.                 temp[i][j]=rand()%2;
  19.             }
  20.             else
  21.             {
  22.                 graph[i][j]=0;
  23.                 temp[i][j]=0;
  24.             }
  25.         }
  26.     }
  27.     for (i=0;i<num_of_nodes;i++)
  28.     {
  29.         for (j=0;j<num_of_nodes;j++)
  30.         {
  31.             if(temp[i][j]==1)
  32.             {
  33.                 temp[j][i]=0;
  34.             }
  35.             printf("%d ", graph[i][j]);
  36.  
  37.         }
  38.         printf("\n");
  39.     }
  40.     for(i=0;i<num_of_nodes;i++)
  41.     {
  42.     for(j=0;j<num_of_nodes;j++)
  43.         {
  44.             if(temp[i][j]==1){
  45.                 number_of_edges++;
  46.             }
  47.         }
  48.     }
  49.     printf("Number Of Edges = %d\n", number_of_edges);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment