I may have mentioned this before, but your indentation needs work.
https://en.wikipedia.org/wiki/Indent_style
Code:
#include<stdio.h>
#define N 10
#define DEBUG 0
#include<time.h>
#include<stdlib.h>
#include<math.h>
int isSafe(int x, int y, int tomb[N][N], int megoldas[N][N])
{
if (x >= 0 && x < N && y >= 0 && y < N && tomb[x][y] == 1 && !megoldas[x][y])
return 1;
else
return 0;
}
int Keres(int tomb[N][N], int megoldas[N][N], int x, int y)
{
if (x == N - 1) {
megoldas[x][y] = 1;
return 1;
}
if (isSafe(x, y, tomb, megoldas) == 1) {
megoldas[x][y] = 1;
if (Keres(tomb, megoldas, x, y + 1) == 1)
return 1;
if (Keres(tomb, megoldas, x + 1, y) == 1)
return 1;
if (Keres(tomb, megoldas, x, y - 1) == 1)
return 1;
if (Keres(tomb, megoldas, x - 1, y) == 1)
return 1;
megoldas[x][y] = 0;
}
return 0;
}
int main()
{
int probalkozas = 100, atment = 0, ok = 0, i, j, k, ism;
float p = 0.0;
float reszatlag[20] = { 0 };
float atlag = 0;
float szoras = 0;
FILE *pFile;
pFile = fopen("10x10.txt", "a");
srand(time(0));
for (int v = 0; v < 10; v++) {
p = p + 0.1;
for (int csinald = 0; csinald < 100; csinald++) {
atment = 0;
int tomb[N][N] = { {0} };
int megoldas[N][N] = { {0} };
for (ism = 0; ism < probalkozas; ism++) {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
if (rand() % 100 + 1 <= (p * 100))
tomb[i][j] = 1;
else
tomb[i][j] = 0;
}
}
ok = 0;
for (i = 0; i < N; i++) {
if (Keres(tomb, megoldas, 0, i) == 1 && ok == 0) {
ok = 1;
atment++;
for (j = 0; j < N; j++) {
for (k = 0; k < N; k++) {
megoldas[j][k] = 0;
}
}
}
}
}
reszatlag[csinald] = (float) atment / (float) probalkozas;
printf("P = %.2f\nTabla kitoltese: %dx\n"
"Sikeres ateresek szama: %d\n"
"Sikeres ateresek atlaga: %.4f \n ",
p, probalkozas, atment, reszatlag[csinald]);
}
for (i = 0; i < 100; i++) {
atlag += reszatlag[i];
}
atlag = atlag / 100;
for (i = 0; i < 110; i++)
szoras = sqrt(((reszatlag[i] - atlag) * (reszatlag[i] - atlag)) / 20);
fprintf(pFile, "%.3f %.4f %.4f\n", p * 100, atlag * 100, szoras * 100);
atlag = 0;
}
return 0;
}
> float reszatlag[20] = ...;
You created a #define for N being 10, why not a #define for the other magic numbers in this code, like 20 and 100 ?
Now the killer....
Code:
for (int csinald = 0; csinald < 100; csinald++)
...
reszatlag[csinald] = (float) atment / (float) probalkozas;
The key phrase here is "buffer overrun!!!"