My program runs, but soon after asking for the value prob()
and .exe
to work.
I thought it was some communication problem between functions because of the lattice[][4]
array as an argument, but I've already tried, fixed, and the same thing still happens. I'm pretty sure the problem is in the communication between main()
and label()
.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int random();
float prob();
int label(float lattice[][4],float);
int i, j;
int random() /* Sorteia um número entre de 0 a 1 */
{
float x;
srand((unsigned)time(NULL));
x = rand()%100+1;
x = x/100;
return x;
}
float prob()
{
float p;
printf("Probabilidade: ");
scanf("%f", &p);
return p;
}
int label(float lattice[][4], float p)
{
for(i=0; i<4 ; i++)
for(j=0; j<4; i++)
{
lattice[i][j] = random();
}
for(i=0; i<4; i++)
for(j=0; j<4; j++)
{
if(lattice[i][j] <= p)
lattice[i][j] = 1;
else
lattice[i][j] = 0;
}
return 0;
}
int main()
{
float lattice[4][4];
float p = prob();
label(lattice, p);
system("pause");
return 0;
}