Guest User

Untitled

a guest
Nov 6th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define n 5
  4. #define m 4
  5. #include <string.h>
  6. typedef int  Graph;
  7. Graph sotto(Graph *a,int in)
  8. {
  9.   int i,j;
  10. Graph *b;
  11. b=(Graph*)calloc(m*m,sizeof(Graph));
  12. for(i=in;i<m;i++)
  13. {
  14.     for(j=in;j<m;j++)
  15.     {
  16.  
  17.         *(b+j*m+i)= *(a+j*m+i);
  18.     }
  19. }
  20. return b;
  21.  
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.  
  28.    Graph *a;
  29.    char nodi[n];
  30.  
  31.    a=(Graph*)calloc(n*n,sizeof(Graph));
  32. short i,j,x;
  33. for(i=0;i<n;i++)
  34. {
  35.     printf("inserisci carattere %d nodo\n",i+1);
  36. fflush(stdin);
  37. scanf("%c",&nodi[i]);
  38. }
  39. for(i=0;i<n;i++)
  40. {
  41.     for(j=0;j<n;j++)
  42.     {if(j!=i){
  43.         printf("se %c e' connesso a %c digita 1 altrimenti 0\n",nodi[i],nodi[j]);
  44.             fflush(stdin);
  45.         scanf("%d",&x);
  46.         if(x==1)
  47.         *(a+j*n+i)=1;
  48.             else
  49.             *(a+j*n+i)=0;}
  50.     }
  51. }
  52. puts("visualizzazione matrice");
  53.  
  54. for(i=0;i<n;i++)
  55. {
  56.     printf("%c: ",nodi[i]);
  57.     for(j=0;j<n;j++)
  58.     {
  59.         printf("[%d] ",*(a+j*n+i));
  60.     }puts("");
  61. }
  62.  
  63.  
  64. puts("visualizzo sottografo B");
  65. Graph *b;
  66. b=sotto(a,1);
  67. for(i=1;i<m;i++)
  68. {
  69.     printf("%c: ",nodi[i]);
  70.     for(j=1;j<m;j++)
  71.     {
  72.         printf("[%d] ",*(b+j*m+i));
  73.     }puts("");
  74. }
  75.  
  76.  
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment