Исправить ошибку в коде - C (СИ) (78988)

Узнай цену своей работы

Формулировка задачи:

написала программу а она выдает ошибку которая повторяется раз пять не знаю как исправить не понимаю почему именно это ошибка помогите исправить
Листинг программы
  1. #include <stdio.h>
  2. #define RAZMER 15
  3.  
  4. int main()
  5. {
  6. int Counter;
  7. int Adjacency[RAZMER][RAZMER] = {{0}};
  8. int Reachability[RAZMER][RAZMER] = {{0}};
  9. int Counter_reachability[RAZMER][RAZMER] = {{0}};
  10. int Mutual_reachability[RAZMER][RAZMER] = {{0}};
  11. int Strong[RAZMER][RAZMER] = {{0}};
  12. int Condens[RAZMER][RAZMER] = {{0}};
  13. int Span[RAZMER][RAZMER] = {{0}};
  14. int i,j;
  15. FILE * inp;
  16. inp = fopen("ishodnik.txt", "r");
  17. for(i = 0; i < RAZMER; i++)
  18. for (j = 0; j < RAZMER; j++)
  19. fscanf(inp, "%d", &Adjacency[i][j]);
  20. printf ("Initial adjacency matrix:\n");
  21. Print_matrix (Adjacency);
  22. Reach_matrix (Adjacency,Reachability);
  23. printf ("Reachability matrix:\n");
  24. Print_matrix (Reachability);
  25. Counter_reach_matrix (Reachability, Counter_reachability);
  26. printf ("Counter reachability matrix:\n");
  27. Print_matrix (Counter_reachability);
  28. Mutual_reach_matrix(Reachability, Mutual_reachability);
  29. printf ("Mutual reachability matrix:\n");
  30. Print_matrix (Mutual_reachability);
  31. Strong_component (Mutual_reachability, Strong);
  32. Condensation (Adjacency, Strong, Condens);
  33. printf ("Condensation:\n");
  34. for(i = 0; i < Counter; i++)
  35. {
  36. for(j = 0; j < Counter; j++)
  37. printf("%d ", Condens[i][j]);
  38. printf("\n");
  39. }
  40. Span_tree (Reachability, Span);
  41. printf("\nSpanning Tree:\n");
  42. Print_matrix(Span);
  43. return 0;
  44. }
  45. void Print_matrix (int *ptr)
  46. {
  47. int i,j;
  48. for(i = 0; i < RAZMER; i++)
  49. {
  50. for(j = 0; j < RAZMER; j++)
  51. printf(" %d", ptr[i*RAZMER+j]);
  52. printf("\n");
  53. }
  54. printf("\nThis matrix is:\n");
  55. if (Reflexive(ptr))
  56. printf("reflexive\n");
  57. else
  58. printf("NOT reflexive\n");
  59. if (Symmetry(ptr))
  60. printf("symmetrical\n");
  61. else
  62. printf("NOT symmetrical\n");
  63. if (Transitive(ptr))
  64. printf("transitive\n");
  65. else
  66. printf("NOT transitive\n");
  67. if (Irreflexive(ptr))
  68. printf("Irreflexive\n");
  69. else
  70. printf("NOT Irreflexive\n");
  71. if (Asymmetry(ptr))
  72. printf("asymmetric\n");
  73. else
  74. printf("NOT asymmetric\n");
  75. if (Antisymmetry(ptr))
  76. printf("antisymmetric\n\n");
  77. else
  78. printf("NOT antisymmetric\n\n");
  79. }
  80. void Assignment (int *ptr1, int *ptr2)
  81. {
  82. int i,j;
  83. for(i = 0; i < RAZMER; i++)
  84. for(j = 0; j < RAZMER; j++)
  85. ptr1[i*RAZMER+j] = ptr2[i*RAZMER+j];
  86. }
  87.  
  88. void Reach_matrix (int *Adjacency_ptr,int *Reachability_ptr){
  89. int i,j,k;
  90. for (k = 0; k < RAZMER; k++)
  91. for (i = 0; i < RAZMER; i++)
  92. for (j = 0; j < RAZMER; j++)
  93. Adjacency_ptr[i*RAZMER+j]+=Adjacency_ptr[i*RAZMER+k]*Adjacency_ptr[k*RAZMER+j]; for (i = 0; i < RAZMER; i++)
  94. for (j = 0; j < RAZMER; j++){
  95. if(Adjacency_ptr[i*RAZMER+j]>=1)
  96. Reachability_ptr[i*RAZMER+j] = 1;
  97. else
  98. Reachability_ptr[i*RAZMER+j] = 0;
  99. Reachability_ptr[i*RAZMER+i] = 1;
  100. }
  101. }
  102. void Counter_reach_matrix (int *Reachability_ptr, int *Counter_reachability_ptr)
  103. {
  104. int i,j;
  105. for (i = 0; i < RAZMER; i++)
  106. for (j = 0; j < RAZMER; j++)
  107. Counter_reachability_ptr[i*RAZMER+j] = Reachability_ptr[j*RAZMER+i];
  108. }
  109. void Mutual_reach_matrix (int *Reachability_ptr, int *Mutual_ptr)
  110. {
  111. int i,j; for (i = 0; i < RAZMER; i++)
  112. for (j = 0; j < RAZMER; j++)
  113. Mutual_ptr[i*RAZMER+j] =Reachability_ptr[i*RAZMER+j]*Reachability_ptr[j*RAZMER+i];
  114. }
  115. int Reflexive(int *ptr){
  116. int i;
  117. for (i = 0; i < RAZMER; i++)
  118. if (ptr[i*RAZMER+i] == 0)
  119. return 0;
  120. return 1;
  121. }
  122. int Symmetry(int *ptr ){
  123. int i, j;
  124. for (i = 0; i < RAZMER; i++)
  125. for (j = 0; j < RAZMER; j++)
  126. if(ptr[i*RAZMER+j] != ptr[j*RAZMER+i])
  127. return 0;
  128. return 1;
  129. }
  130. int Transitive(int *ptr){
  131. int k, i, j;
  132. for (i = 0; i < RAZMER; i++)
  133. for (j = 0; j < RAZMER; j++)
  134. for (k = 0; k < RAZMER; k++)
  135. if(ptr[i*RAZMER+j] == 1 && ptr[j*RAZMER+k] == 1 && ptr[i*RAZMER+k] != 1)
  136. return 0;
  137. return 1;
  138. }
  139. int Irreflexive(int *ptr){
  140. int i;
  141. for (i = 0; i < RAZMER; i++)
  142. if (ptr[i*RAZMER+i] != 0)
  143. return 0;
  144. return 1;
  145. }
  146. int Asymmetry(int *ptr) {
  147. int i, j;
  148. for (i = 0; i < RAZMER; i++)
  149. for (j = 0; j < RAZMER; j++)
  150. if((ptr[i*RAZMER+j]!=0) && (ptr[i*RAZMER+j] == ptr[j*RAZMER+i]))
  151. return 0;
  152. return 1;
  153. }
  154.  
  155. int Antisymmetry (int *ptr){
  156. int i, j;
  157. for (i = 0; i < RAZMER; i++)
  158. for (j = 0; j < RAZMER; j++)
  159. if (ptr[i*RAZMER+j] == 1 && ptr[j*RAZMER+i] == 1 && i!=j)
  160. return 0;
  161. return 1;
  162. }
  163.  
  164. void Strong_component (int *Mutual_ptr, int *Strongly_ptr)
  165. {
  166. int i, j, k, Counter;
  167. int Mutual_counter[RAZMER][RAZMER] = {{0}};
  168. int Strong_counter[RAZMER][RAZMER] = {{0}};
  169. Assignment (Mutual_counter, Mutual_ptr);
  170. for (j = 0; j < RAZMER; j++)
  171. {
  172. for (i = 0; i < RAZMER; i++)
  173. for (k = 0; k < RAZMER; k++)
  174. if ((Mutual_counter[k][j] == Mutual_counter[i][j]) && (Mutual_counter[k][j] == 1) && (k > i))
  175. for (Counter = 0; Counter < RAZMER; Counter++)
  176. Mutual_counter[k][Counter] = 0;
  177. Counter = 0
  178. for (i = 0; i < RAZMER; i++)
  179. Counter+= Mutual_counter[j][i];
  180. if (Counter >= 1)
  181. for (i = 0; i < RAZMER; i++)
  182. Strong_counter[j][i] = Mutual_counter[j][i];
  183. }
  184. for (k = 0; k < RAZMER; k++)
  185. {
  186. for (i = 0; i < RAZMER-1; i++)
  187. {
  188. Counter = 0;
  189. for (j = 0; j < RAZMER; j++)
  190. Counter+= Strong_counter[i][j];
  191. if (Counter == 0){
  192. for (j = 0; j < RAZMER; j++)
  193. {
  194. Strong_counter[i][j] = Strong_counter[i+1][j];
  195. Strong_counter[i+1][j] = 0;
  196. }
  197. }
  198. }
  199. for (j = 0; j < RAZMER; j++)
  200. if (Strong_counter[k][j] !=0)
  201. Strong_counter[k][j] = j+1;
  202. }
  203. for (i = 0; i < RAZMER; i++)
  204. {
  205. for (j = 0; j < RAZMER; j++)
  206. if (Strong_counter[i][j] !=0)
  207. {
  208. Strongly_ptr[i*RAZMER+Counter] = Strong_counter[i][j];
  209. Counter++;
  210. }
  211. Counter = 0;
  212. }
  213. Counter = 0;
  214. for (i = 0; i < RAZMER; i++)
  215. for (j = 0; j < RAZMER; j++)
  216. if (Strong_counter[i][j] !=0)
  217. {
  218. Counter++;
  219. break;
  220. }
  221. printf ("Strongly connected components:\n\n");
  222. for (i = 0; i < Counter; i++)
  223. {
  224. printf("Component #%d:\n{", i+1);
  225. for(j = 0; j < RAZMER; j++)
  226. printf("%d,", Strongly_ptr[i*RAZMER+j]);
  227. printf("}\n\n");
  228. }
  229. }
  230.  
  231. void Condensation (int *Adjacency_ptr, int *Strongly_ptr, int *Condensation_ptr){
  232. int i,j,k,l;
  233. for (i = 0; i < RAZMER; i++)
  234. for (j = 0; j < RAZMER; j++)
  235. if (Strongly_ptr[i*RAZMER+j] != 0)
  236. for (k = 0; k < RAZMER; k++)
  237. for (l = 0; l < RAZMER; l++)
  238. if ((k != i) && (Strongly_ptr[k*RAZMER+l] != 0) && (Adjacency_ptr[Strongly_ptr[i*RAZMER+j]*RAZMER+Strongly_ptr[k*RAZMER+l]] == 1))
  239. Condensation_ptr[i*RAZMER+k] = 1;
  240. }
  241. void Span_tree (int *Adjacency_ptr, int *Span_ptr){
  242. int i,j,k,l,m, Stack[RAZMER] = {0}, Stack_number = 0;
  243. Stack[0] = 6; for (i = 0; i < RAZMER; i++)
  244. Span_ptr[i*RAZMER+Stack[0]] = 0;
  245. while(Stack_number <= RAZMER-1){
  246. for (i = 0; i < RAZMER; i++)
  247. if (Span_ptr[Stack[Stack_number]*RAZMER+i] == 1)
  248. for (j = 0; j < RAZMER; j++)
  249. if ((Span_ptr[j*RAZMER+i] == 1) && (j != Stack[Stack_number]))
  250. Span_ptr[j*RAZMER+i] = 0;
  251. ++Stack_number;
  252. Stack[Stack_number] = Stack_number;
  253. }
  254. }
компилятор выдает
Листинг программы
  1. error: conflicting types for 'Print_matrix'
  2. error: previous implicit declaration of 'Print_matrix' was here
  3. error: conflicting types for 'Reach_matrix'
  4. error: previous implicit declaration of 'Reach_matrix' was here
  5. : error: conflicting types for 'Counter_reach_matrix'
  6. error: previous implicit declaration of 'Counter_reach_matrix' was
  7.  
  8. : error: conflicting types for 'Mutual_reach_matrix'
  9. error: previous implicit declaration of 'Mutual_reach_matrix' was
  10.  
  11. : error: conflicting types for 'Strong_component'
  12. error: previous implicit declaration of 'Strong_component' was her
  13.  
  14. function `Strong_component':
  15. : warning: passing arg 1 of `Assignment' from incompatible pointer
  16.  
  17. : error: syntax error before "for"
  18. : error: syntax error before ')' token
  19. top level:
  20. : error: conflicting types for 'Condensation'
  21. error: previous implicit declaration of 'Condensation' was here
  22. : error: conflicting types for 'Span_tree'
  23. error: previous implicit declaration of 'Span_tree' was here

Решение задачи: «Исправить ошибку в коде»

textual
Листинг программы
  1. printf ("Initial adjacency matrix:\n");
  2.  Print_matrix ((int*)Adjacency);
  3.  Reach_matrix ((int*)Adjacency, (int*)Reachability);
  4.  printf ("Reachability matrix:\n");
  5.  Print_matrix ((int*)Reachability);
  6.  Counter_reach_matrix ((int*)Reachability, (int*)Counter_reachability);
  7.  printf ("Counter reachability matrix:\n");
  8.  Print_matrix ((int*)Counter_reachability);
  9.  Mutual_reach_matrix((int*)Reachability, (int*)Mutual_reachability);
  10.  printf ("Mutual reachability matrix:\n");
  11.  Print_matrix ((int*)Mutual_reachability);
  12.  Strong_component ((int*)Mutual_reachability, (int*)Strong);
  13.  Condensation ((int*)Adjacency, (int*)Strong, Condens);
  14.  printf ("Condensation:\n");
  15.  for(i = 0; i < Counter; i++)
  16. {
  17.  for(j = 0; j < Counter; j++)
  18.  printf("%d ", Condens[i][j]);
  19.  printf("\n");
  20.  }
  21.  Span_tree ((int*)Reachability, (int*)Span);
  22.  printf("\nSpanning Tree:\n");
  23.  Print_matrix((int*)Span);
  24.  return 0;

Объяснение кода листинга программы

  1. Выводится исходная матрица смежности.
  2. Вычисляется матрица достижимости.
  3. Выводится матрица достижимости.
  4. Вычисляется матрица взаимной достижимости.
  5. Выводится матрица взаимной достижимости.
  6. Вычисляется матрица сильных компонент.
  7. Вычисляется матрица конденсации.
  8. Выводится матрица конденсации.
  9. Вычисляется дерево вложения.
  10. Выводится дерево вложения.
  11. Вычисляется дерево достижимости.
  12. Выводится дерево достижимости.
  13. Вычисляется матрица достижимости графа вложения.
  14. Выводится матрица достижимости графа вложения.
  15. Вычисляется матрица взаимной достижимости графа вложения.
  16. Выводится матрица взаимной достижимости графа вложения.
  17. Вычисляется матрица сильных компонент графа вложения.
  18. Выводится матрица сильных компонент графа вложения.
  19. Вычисляется матрица конденсации графа вложения.
  20. Выводится матрица конденсации графа вложения.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут