Исправить ошибку в коде - C (СИ) (78988)
Формулировка задачи:
написала программу а она выдает ошибку которая повторяется раз пять не знаю как исправить не понимаю почему именно это ошибка помогите исправить
компилятор выдает
#include <stdio.h>
#define RAZMER 15
int main()
{
int Counter;
int Adjacency[RAZMER][RAZMER] = {{0}};
int Reachability[RAZMER][RAZMER] = {{0}};
int Counter_reachability[RAZMER][RAZMER] = {{0}};
int Mutual_reachability[RAZMER][RAZMER] = {{0}};
int Strong[RAZMER][RAZMER] = {{0}};
int Condens[RAZMER][RAZMER] = {{0}};
int Span[RAZMER][RAZMER] = {{0}};
int i,j;
FILE * inp;
inp = fopen("ishodnik.txt", "r");
for(i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
fscanf(inp, "%d", &Adjacency[i][j]);
printf ("Initial adjacency matrix:\n");
Print_matrix (Adjacency);
Reach_matrix (Adjacency,Reachability);
printf ("Reachability matrix:\n");
Print_matrix (Reachability);
Counter_reach_matrix (Reachability, Counter_reachability);
printf ("Counter reachability matrix:\n");
Print_matrix (Counter_reachability);
Mutual_reach_matrix(Reachability, Mutual_reachability);
printf ("Mutual reachability matrix:\n");
Print_matrix (Mutual_reachability);
Strong_component (Mutual_reachability, Strong);
Condensation (Adjacency, Strong, Condens);
printf ("Condensation:\n");
for(i = 0; i < Counter; i++)
{
for(j = 0; j < Counter; j++)
printf("%d ", Condens[i][j]);
printf("\n");
}
Span_tree (Reachability, Span);
printf("\nSpanning Tree:\n");
Print_matrix(Span);
return 0;
}
void Print_matrix (int *ptr)
{
int i,j;
for(i = 0; i < RAZMER; i++)
{
for(j = 0; j < RAZMER; j++)
printf(" %d", ptr[i*RAZMER+j]);
printf("\n");
}
printf("\nThis matrix is:\n");
if (Reflexive(ptr))
printf("reflexive\n");
else
printf("NOT reflexive\n");
if (Symmetry(ptr))
printf("symmetrical\n");
else
printf("NOT symmetrical\n");
if (Transitive(ptr))
printf("transitive\n");
else
printf("NOT transitive\n");
if (Irreflexive(ptr))
printf("Irreflexive\n");
else
printf("NOT Irreflexive\n");
if (Asymmetry(ptr))
printf("asymmetric\n");
else
printf("NOT asymmetric\n");
if (Antisymmetry(ptr))
printf("antisymmetric\n\n");
else
printf("NOT antisymmetric\n\n");
}
void Assignment (int *ptr1, int *ptr2)
{
int i,j;
for(i = 0; i < RAZMER; i++)
for(j = 0; j < RAZMER; j++)
ptr1[i*RAZMER+j] = ptr2[i*RAZMER+j];
}
void Reach_matrix (int *Adjacency_ptr,int *Reachability_ptr){
int i,j,k;
for (k = 0; k < RAZMER; k++)
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
Adjacency_ptr[i*RAZMER+j]+=Adjacency_ptr[i*RAZMER+k]*Adjacency_ptr[k*RAZMER+j]; for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++){
if(Adjacency_ptr[i*RAZMER+j]>=1)
Reachability_ptr[i*RAZMER+j] = 1;
else
Reachability_ptr[i*RAZMER+j] = 0;
Reachability_ptr[i*RAZMER+i] = 1;
}
}
void Counter_reach_matrix (int *Reachability_ptr, int *Counter_reachability_ptr)
{
int i,j;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
Counter_reachability_ptr[i*RAZMER+j] = Reachability_ptr[j*RAZMER+i];
}
void Mutual_reach_matrix (int *Reachability_ptr, int *Mutual_ptr)
{
int i,j; for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
Mutual_ptr[i*RAZMER+j] =Reachability_ptr[i*RAZMER+j]*Reachability_ptr[j*RAZMER+i];
}
int Reflexive(int *ptr){
int i;
for (i = 0; i < RAZMER; i++)
if (ptr[i*RAZMER+i] == 0)
return 0;
return 1;
}
int Symmetry(int *ptr ){
int i, j;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
if(ptr[i*RAZMER+j] != ptr[j*RAZMER+i])
return 0;
return 1;
}
int Transitive(int *ptr){
int k, i, j;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
for (k = 0; k < RAZMER; k++)
if(ptr[i*RAZMER+j] == 1 && ptr[j*RAZMER+k] == 1 && ptr[i*RAZMER+k] != 1)
return 0;
return 1;
}
int Irreflexive(int *ptr){
int i;
for (i = 0; i < RAZMER; i++)
if (ptr[i*RAZMER+i] != 0)
return 0;
return 1;
}
int Asymmetry(int *ptr) {
int i, j;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
if((ptr[i*RAZMER+j]!=0) && (ptr[i*RAZMER+j] == ptr[j*RAZMER+i]))
return 0;
return 1;
}
int Antisymmetry (int *ptr){
int i, j;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
if (ptr[i*RAZMER+j] == 1 && ptr[j*RAZMER+i] == 1 && i!=j)
return 0;
return 1;
}
void Strong_component (int *Mutual_ptr, int *Strongly_ptr)
{
int i, j, k, Counter;
int Mutual_counter[RAZMER][RAZMER] = {{0}};
int Strong_counter[RAZMER][RAZMER] = {{0}};
Assignment (Mutual_counter, Mutual_ptr);
for (j = 0; j < RAZMER; j++)
{
for (i = 0; i < RAZMER; i++)
for (k = 0; k < RAZMER; k++)
if ((Mutual_counter[k][j] == Mutual_counter[i][j]) && (Mutual_counter[k][j] == 1) && (k > i))
for (Counter = 0; Counter < RAZMER; Counter++)
Mutual_counter[k][Counter] = 0;
Counter = 0
for (i = 0; i < RAZMER; i++)
Counter+= Mutual_counter[j][i];
if (Counter >= 1)
for (i = 0; i < RAZMER; i++)
Strong_counter[j][i] = Mutual_counter[j][i];
}
for (k = 0; k < RAZMER; k++)
{
for (i = 0; i < RAZMER-1; i++)
{
Counter = 0;
for (j = 0; j < RAZMER; j++)
Counter+= Strong_counter[i][j];
if (Counter == 0){
for (j = 0; j < RAZMER; j++)
{
Strong_counter[i][j] = Strong_counter[i+1][j];
Strong_counter[i+1][j] = 0;
}
}
}
for (j = 0; j < RAZMER; j++)
if (Strong_counter[k][j] !=0)
Strong_counter[k][j] = j+1;
}
for (i = 0; i < RAZMER; i++)
{
for (j = 0; j < RAZMER; j++)
if (Strong_counter[i][j] !=0)
{
Strongly_ptr[i*RAZMER+Counter] = Strong_counter[i][j];
Counter++;
}
Counter = 0;
}
Counter = 0;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
if (Strong_counter[i][j] !=0)
{
Counter++;
break;
}
printf ("Strongly connected components:\n\n");
for (i = 0; i < Counter; i++)
{
printf("Component #%d:\n{", i+1);
for(j = 0; j < RAZMER; j++)
printf("%d,", Strongly_ptr[i*RAZMER+j]);
printf("}\n\n");
}
}
void Condensation (int *Adjacency_ptr, int *Strongly_ptr, int *Condensation_ptr){
int i,j,k,l;
for (i = 0; i < RAZMER; i++)
for (j = 0; j < RAZMER; j++)
if (Strongly_ptr[i*RAZMER+j] != 0)
for (k = 0; k < RAZMER; k++)
for (l = 0; l < RAZMER; l++)
if ((k != i) && (Strongly_ptr[k*RAZMER+l] != 0) && (Adjacency_ptr[Strongly_ptr[i*RAZMER+j]*RAZMER+Strongly_ptr[k*RAZMER+l]] == 1))
Condensation_ptr[i*RAZMER+k] = 1;
}
void Span_tree (int *Adjacency_ptr, int *Span_ptr){
int i,j,k,l,m, Stack[RAZMER] = {0}, Stack_number = 0;
Stack[0] = 6; for (i = 0; i < RAZMER; i++)
Span_ptr[i*RAZMER+Stack[0]] = 0;
while(Stack_number <= RAZMER-1){
for (i = 0; i < RAZMER; i++)
if (Span_ptr[Stack[Stack_number]*RAZMER+i] == 1)
for (j = 0; j < RAZMER; j++)
if ((Span_ptr[j*RAZMER+i] == 1) && (j != Stack[Stack_number]))
Span_ptr[j*RAZMER+i] = 0;
++Stack_number;
Stack[Stack_number] = Stack_number;
}
}error: conflicting types for 'Print_matrix' error: previous implicit declaration of 'Print_matrix' was here error: conflicting types for 'Reach_matrix' error: previous implicit declaration of 'Reach_matrix' was here : error: conflicting types for 'Counter_reach_matrix' error: previous implicit declaration of 'Counter_reach_matrix' was : error: conflicting types for 'Mutual_reach_matrix' error: previous implicit declaration of 'Mutual_reach_matrix' was : error: conflicting types for 'Strong_component' error: previous implicit declaration of 'Strong_component' was her function `Strong_component': : warning: passing arg 1 of `Assignment' from incompatible pointer : error: syntax error before "for" : error: syntax error before ')' token top level: : error: conflicting types for 'Condensation' error: previous implicit declaration of 'Condensation' was here : error: conflicting types for 'Span_tree' error: previous implicit declaration of 'Span_tree' was here
Решение задачи: «Исправить ошибку в коде»
textual
Листинг программы
printf ("Initial adjacency matrix:\n");
Print_matrix ((int*)Adjacency);
Reach_matrix ((int*)Adjacency, (int*)Reachability);
printf ("Reachability matrix:\n");
Print_matrix ((int*)Reachability);
Counter_reach_matrix ((int*)Reachability, (int*)Counter_reachability);
printf ("Counter reachability matrix:\n");
Print_matrix ((int*)Counter_reachability);
Mutual_reach_matrix((int*)Reachability, (int*)Mutual_reachability);
printf ("Mutual reachability matrix:\n");
Print_matrix ((int*)Mutual_reachability);
Strong_component ((int*)Mutual_reachability, (int*)Strong);
Condensation ((int*)Adjacency, (int*)Strong, Condens);
printf ("Condensation:\n");
for(i = 0; i < Counter; i++)
{
for(j = 0; j < Counter; j++)
printf("%d ", Condens[i][j]);
printf("\n");
}
Span_tree ((int*)Reachability, (int*)Span);
printf("\nSpanning Tree:\n");
Print_matrix((int*)Span);
return 0;
Объяснение кода листинга программы
- Выводится исходная матрица смежности.
- Вычисляется матрица достижимости.
- Выводится матрица достижимости.
- Вычисляется матрица взаимной достижимости.
- Выводится матрица взаимной достижимости.
- Вычисляется матрица сильных компонент.
- Вычисляется матрица конденсации.
- Выводится матрица конденсации.
- Вычисляется дерево вложения.
- Выводится дерево вложения.
- Вычисляется дерево достижимости.
- Выводится дерево достижимости.
- Вычисляется матрица достижимости графа вложения.
- Выводится матрица достижимости графа вложения.
- Вычисляется матрица взаимной достижимости графа вложения.
- Выводится матрица взаимной достижимости графа вложения.
- Вычисляется матрица сильных компонент графа вложения.
- Выводится матрица сильных компонент графа вложения.
- Вычисляется матрица конденсации графа вложения.
- Выводится матрица конденсации графа вложения.