fork download
  1. #include<stdlib.h>
  2. #define nul 1000
  3. #define nodes 10
  4.  
  5. int no;
  6.  
  7. struct node
  8. {
  9. int a [nodes][4];
  10. }
  11. router [nodes];
  12. void init(int r)
  13. {
  14. int i ;
  15. for (i=1;i<=no;i++)
  16. {
  17. router[r].a[i][1]=i;
  18. router[r].a[i][2]=999;
  19. router[r].a[i][3]=nul;
  20. }printf("\n\t\t\t %d\t no link \t no hop",router[r].a[i][1]);
  21. else
  22. printf("\n\t\t%d\t%d\t\t d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
  23. }
  24. }
  25. void dv_algo(int r)
  26. {include<stdlib.h>
  27. #define nul 1000
  28. #defi
  29. {
  30. int i,j,z ;
  31. for(i=1;i<=no;i++)
  32. {
  33. if(router[r].a[i][2]!=999 && router[r].a[i][2]!=0)
  34. {
  35. for(j=1;j<=no;j++)include<stdlib.h>
  36. #define nul 1000
  37. #defi
  38. {
  39. z=router[r].a[i][2]+router[i].a[j][2];
  40. if(router[r].a[j][2]>z)
  41. {
  42. router[r].a[j][2]=z;
  43. router[r].a[j][3]=i;
  44. }
  45. }
  46. }
  47. }include<stdlib.h>
  48. #define nul 1000
  49. #defi
  50. }
  51. }
  52. int main()
  53. {
  54.  
  55. router[r].a[r][2]=0;
  56. router[r].a[r][3]=r;
  57. }
  58.  
  59. void inp(int r)
  60. {
  61. int i;
  62. printf("\n Enter dist from the node %d to other nodes",r);
  63. printf("\n pls enter 999 if there is no direct routr \n",r);
  64. for(i=1;i<=no;i++)
  65. {
  66. if(i!=r)
  67. {
  68. printf("\n Enter dist to the nodes %d:",i);
  69. scanf("%d",&router[r].a[i][2]);
  70. router[r].a[i][3]=i;
  71. }
  72. }
  73. }
  74. void display (int r)
  75. {
  76. int i,j;
  77. printf("\n\n The routing table for nodes %d is as follows:",r);
  78. printf("\n\t\t\t %d\t no link \t no hop",router[r].a[i][1]);
  79. else
  80. printf("\n\t\t%d\t%d\t\t d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
  81. }
  82. }
  83. void dv_algo(int r)
  84. {include<stdlib.h>
  85. #define nul 1000
  86. #defi
  87. {
  88. int i,j,z ;
  89. for(i=1;i<=no;i++)
  90. {
  91. if(router[r].a[i][2]!=999 && router[r].a[i][2]!=0)
  92. {
  93. for(j=1;j<=no;j++)include<stdlib.h>
  94. #define nul 1000
  95. #defi
  96. {
  97. z=router[r].a[i][2]+router[i].a[j][2];
  98. if(router[r].a[j][2]>z)
  99. {
  100. router[r].a[j][2]=z;
  101. router[r].a[j][3]=i;
  102. }
  103. }
  104. }
  105. }include<stdlib.h>
  106. #define nul 1000
  107. #defi
  108. }
  109. }
  110. int main()
  111. {
  112. int i,j,x,y;
  113. char choice;
  114. printf("\nEnter the no of nodes required (less than 10 pls):");
  115. scanf("%d",&no);
  116. for(i=1;i<=no;i++)
  117. {
  118. init(i);
  119. inp(i);
  120. }
  121. printf("\nThe configuration of the nodes after initialization is as follows:");
  122. for(i=1;i<=no;i++)
  123. display(i);
  124. for(i=1;i<=no;i++)
  125.  
  126. dv_algo(i);
  127. printf("\n The configuration of the nodes after computation of paths is as follows:");
  128. for(i=1;i<=no;i++)
  129. display(i);
  130. while(1)
  131. {
  132. printf("\n\nWanna continue (y/n):");
  133. scanf("%c",&choice);
  134. if(choice=='n')
  135. break;
  136. printf("\nEnter the nodes btn which shortest path is to be found:\n");
  137. scanf("%d%d,&x,&y");
  138. printf("\nThe length of the shortest path is %include<stdlib.h>
  139. #define nul 1000
  140. #defid",router[x].a[y][2]);
  141. }
  142. return 0;
  143. }for(i=1;i<=no;i++)
  144. {
  145. if(router[r].a[i][2]>=999)
  146. printf("\n\t\t\t %d\t no link \t no hop",router[r].a[i][1]);
  147. else
  148. printf("\n\t\t%d\t%d\t\t d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
  149. }
  150. }
  151. void dv_algo(int r)
  152. {include<stdlib.h>
  153. #define nul 1000
  154. #defi
  155. {
  156. int i,j,z ;
  157. for(i=1;i<=no;i++)
  158. {
  159. if(router[r].a[i][2]!=999 && router[r].a[i][2]!=0)
  160. {
  161. for(j=1;j<=no;j++)include<stdlib.h>
  162. #define nul 1000
  163. #defi
  164. {
  165. z=router[r].a[i][2]+router[i].a[j][2];
  166. if(router[r].a[j][2]>z)
  167. {
  168. router[r].a[j][2]=z;
  169. router[r].a[j][3]=i;
  170. }
  171. }
  172. }
  173. }include<stdlib.h>
  174. #define nul 1000
  175. #defi
  176. }
  177. }
  178. int main()
  179. {
  180. int i,j,x,y;
  181. char choice;
  182. printf("\nEnter the no of nodes required (less than 10 pls):");
  183. scanf("%d",&no);
  184. for(i=1;i<=no;i++)
  185. {
  186. init(i);
  187. inp(i);
  188. }
  189. printf("\nThe configuration of the nodes after initialization is as follows:");
  190. for(i=1;i<=no;i++)
  191. display(i);
  192. for(i=1;i<=no;i++)
  193.  
  194. dv_algo(i);
  195. printf("\n The configuration of the nodes after computation of paths is as follows:");
  196. for(i=1;i<=no;i++)
  197. display(i);
  198. while(1)
  199. {
  200. printf("\n\nWanna continue (y/n):");
  201. scanf("%c",&choice);
  202. if(choice=='n')
  203. break;
  204. printf("\nEnter the nodes btn which shortest path is to be found:\n");
  205. scanf("%d%d,&x,&y");
  206. printf("\nThe length of the shortest path is %include<stdlib.h>
  207. #define nul 1000
  208. #defid",router[x].a[y][2]);
  209. }
  210. return 0;
  211. }
  212.  
  213.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘init’:
prog.c:20:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
 }printf("\n\t\t\t %d\t no link \t no hop",router[r].a[i][1]);
  ^~~~~~
prog.c:20:2: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:20:2: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c:21:1: error: ‘else’ without a previous ‘if’
 else
 ^~~~
prog.c:22:8: warning: too many arguments for format [-Wformat-extra-args]
 printf("\n\t\t%d\t%d\t\t d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
        ^~~~~~~~~~~~~~~~~~~~
prog.c: At top level:
prog.c:24:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
prog.c: In function ‘dv_algo’:
prog.c:26:2: error: ‘include’ undeclared (first use in this function)
 {include<stdlib.h>
  ^~~~~~~
prog.c:26:2: note: each undeclared identifier is reported only once for each function it appears in
prog.c:26:10: error: ‘stdlib’ undeclared (first use in this function)
 {include<stdlib.h>
          ^~~~~~
prog.c:28:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:29:1: error: expected expression before ‘{’ token
 {
 ^
prog.c:37:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:49:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c: In function ‘main’:
prog.c:55:8: error: ‘r’ undeclared (first use in this function)
 router[r].a[r][2]=0;
        ^
prog.c: In function ‘inp’:
prog.c:62:1: warning: incompatible implicit declaration of built-in function ‘printf’
 printf("\n Enter dist from the node %d to other nodes",r);
 ^~~~~~
prog.c:62:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c:63:8: warning: too many arguments for format [-Wformat-extra-args]
 printf("\n pls enter 999 if there is no direct routr \n",r);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:69:1: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
 scanf("%d",&router[r].a[i][2]);
 ^~~~~
prog.c:69:1: warning: incompatible implicit declaration of built-in function ‘scanf’
prog.c:69:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
prog.c: In function ‘display’:
prog.c:77:1: warning: incompatible implicit declaration of built-in function ‘printf’
 printf("\n\n The routing table for nodes %d is as follows:",r);
 ^~~~~~
prog.c:77:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c:79:1: error: ‘else’ without a previous ‘if’
 else
 ^~~~
prog.c:80:8: warning: too many arguments for format [-Wformat-extra-args]
 printf("\n\t\t%d\t%d\t\t d",router[r].a[i][1],router[r].a[i][2],router[r].a[i][3]);
        ^~~~~~~~~~~~~~~~~~~~
prog.c:76:7: warning: unused variable ‘j’ [-Wunused-variable]
 int i,j;
       ^
prog.c: At top level:
prog.c:82:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
prog.c:83:6: error: redefinition of ‘dv_algo’
 void dv_algo(int r)
      ^~~~~~~
prog.c:25:6: note: previous definition of ‘dv_algo’ was here
 void dv_algo(int r)
      ^~~~~~~
prog.c: In function ‘dv_algo’:
prog.c:84:2: error: ‘include’ undeclared (first use in this function)
 {include<stdlib.h>
  ^~~~~~~
prog.c:84:10: error: ‘stdlib’ undeclared (first use in this function)
 {include<stdlib.h>
          ^~~~~~
prog.c:86:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:87:1: error: expected expression before ‘{’ token
 {
 ^
prog.c:95:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:107:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c: At top level:
prog.c:110:5: error: redefinition of ‘main’
 int main()
     ^~~~
prog.c:52:5: note: previous definition of ‘main’ was here
 int main()
     ^~~~
prog.c: In function ‘main’:
prog.c:114:1: warning: incompatible implicit declaration of built-in function ‘printf’
 printf("\nEnter the no of nodes required (less than 10 pls):");
 ^~~~~~
prog.c:114:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c:115:1: warning: incompatible implicit declaration of built-in function ‘scanf’
 scanf("%d",&no);
 ^~~~~
prog.c:115:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
prog.c:137:9: warning: format ‘%d’ expects a matching ‘int *’ argument [-Wformat=]
 scanf("%d%d,&x,&y");
         ^
prog.c:137:11: warning: format ‘%d’ expects a matching ‘int *’ argument [-Wformat=]
 scanf("%d%d,&x,&y");
           ^
prog.c:138:8: warning: missing terminating " character
 printf("\nThe length of the shortest path is %include<stdlib.h>
        ^
prog.c:138:8: error: missing terminating " character
 printf("\nThe length of the shortest path is %include<stdlib.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:140:2: error: invalid preprocessing directive #defid
 #defid",router[x].a[y][2]);
  ^~~~~
prog.c:140:7: warning: missing terminating " character
 #defid",router[x].a[y][2]);
       ^
prog.c:141:1: error: expected expression before ‘}’ token
 }
 ^
prog.c:141:1: error: expected ‘;’ before ‘}’ token
prog.c:112:11: warning: unused variable ‘y’ [-Wunused-variable]
 int i,j,x,y;
           ^
prog.c:112:9: warning: unused variable ‘x’ [-Wunused-variable]
 int i,j,x,y;
         ^
prog.c:112:7: warning: unused variable ‘j’ [-Wunused-variable]
 int i,j,x,y;
       ^
prog.c: At top level:
prog.c:143:2: error: expected identifier or ‘(’ before ‘for’
 }for(i=1;i<=no;i++)
  ^~~
prog.c:143:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<=’ token
 }for(i=1;i<=no;i++)
           ^~
prog.c:143:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘++’ token
 }for(i=1;i<=no;i++)
                 ^~
prog.c:150:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
prog.c:151:6: error: redefinition of ‘dv_algo’
 void dv_algo(int r)
      ^~~~~~~
prog.c:25:6: note: previous definition of ‘dv_algo’ was here
 void dv_algo(int r)
      ^~~~~~~
prog.c: In function ‘dv_algo’:
prog.c:152:2: error: ‘include’ undeclared (first use in this function)
 {include<stdlib.h>
  ^~~~~~~
prog.c:152:10: error: ‘stdlib’ undeclared (first use in this function)
 {include<stdlib.h>
          ^~~~~~
prog.c:154:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:155:1: error: expected expression before ‘{’ token
 {
 ^
prog.c:163:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c:175:2: error: invalid preprocessing directive #defi
 #defi
  ^~~~
prog.c: At top level:
prog.c:178:5: error: redefinition of ‘main’
 int main()
     ^~~~
prog.c:52:5: note: previous definition of ‘main’ was here
 int main()
     ^~~~
prog.c: In function ‘main’:
prog.c:182:1: warning: incompatible implicit declaration of built-in function ‘printf’
 printf("\nEnter the no of nodes required (less than 10 pls):");
 ^~~~~~
prog.c:182:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c:183:1: warning: incompatible implicit declaration of built-in function ‘scanf’
 scanf("%d",&no);
 ^~~~~
prog.c:183:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
prog.c:205:9: warning: format ‘%d’ expects a matching ‘int *’ argument [-Wformat=]
 scanf("%d%d,&x,&y");
         ^
prog.c:205:11: warning: format ‘%d’ expects a matching ‘int *’ argument [-Wformat=]
 scanf("%d%d,&x,&y");
           ^
prog.c:206:8: warning: missing terminating " character
 printf("\nThe length of the shortest path is %include<stdlib.h>
        ^
prog.c:206:8: error: missing terminating " character
 printf("\nThe length of the shortest path is %include<stdlib.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:208:2: error: invalid preprocessing directive #defid
 #defid",router[x].a[y][2]);
  ^~~~~
prog.c:208:7: warning: missing terminating " character
 #defid",router[x].a[y][2]);
       ^
prog.c:209:1: error: expected expression before ‘}’ token
 }
 ^
prog.c:209:1: error: expected ‘;’ before ‘}’ token
prog.c:180:11: warning: unused variable ‘y’ [-Wunused-variable]
 int i,j,x,y;
           ^
prog.c:180:9: warning: unused variable ‘x’ [-Wunused-variable]
 int i,j,x,y;
         ^
prog.c:180:7: warning: unused variable ‘j’ [-Wunused-variable]
 int i,j,x,y;
       ^
stdout
Standard output is empty