Zdravim potreboval bych poradit ohledne tisknuti vysledku. Tiskne mi to same nuly, zatimco kdyz dam misto tucne zvyrazneneho radku (viz zdrojak) napriklad: printf("%6i %10i %7.2f %10i %7.2f\n", n, pocet_srovnani, pocet_srovnani / (n * log(n)/log(2)), pocet_presunu, pocet_presunu / (n * log(n)/log(2))); tak to vysledky vypocita normalne, ale kdyz tam dam pouze n, tak nuly....nevite kde je problem?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int pocet_srovnani, pocet_presunu;
void UdelejPole(int A[], int n) {
int i;
for (i = 0; i < n; i++)
A[i] = rand();
}
void SelecttionSort(int A[], int n) {
int i, j, k;
int x;
for (i = 0; i < n-1; i++)
{
k=i;
x=A[i];
for (j = i+1; j<n; j++)
pocet_srovnani++;
if (A[j]<x)
{
k=j;
x=A[j];
}
A[k]=A[i];
pocet_presunu++;
A[i]=x;
}
}
int main()
{
int i;
int cisla[9] = {10,20,50,100,200, 500, 1000, 2000,5000};
srand((int)time(0));
printf("%7s %16s %18s\n----------------------------------------------\n", "pocet", "srovnani", "presuny");
for (i = 0; i < 9; i++) {
int n = cisla[i];
int pole[n];
UdelejPole(pole, n);
SelecttionSort(pole, n);
printf("%6d %10d %7.2f %10d %7.2f \n", n, pocet_srovani, pocet_srovnani / n, pocet_presunu, pocet_presunu / n );
pocet_srovnani = 0;
pocet_presunu = 0;
if (i == 8) {
printf("prvni cisla: \n");
for (i = 0; i < 20; i++)
printf(" %i ", pole[i]);
printf("\n\n posledni cisla: \n ");
for (i = n-10; i < n; i++)
printf(", %i", pole[i]);
}
}
return 0;
}