/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int dlugosc_tab;
void wprowadz_dlugosc(int *tab);
void sprawdz_dlugosc(int *tab);
void insertion_sort(int *tab);
void losuj_liczby(int *tab);
void wyswietl_tab(int *tab);
int main()
{
sprawdz_dlugosc(&dlugosc_tab);
printf ("\nDługość :%d\n",dlugosc_tab);
int * tab = malloc(sizeof *tab * (dlugosc_tab + 1));
if (!tab)
{
perror("malloc");
return -1;
}
srand (time(NULL));
losuj_liczby(tab);
wyswietl_tab(tab);
free(tab);
}
void wprowadz_dlugosc(int *tab){
printf ("\nPodaj długość :");
scanf("%d",&(*tab));
return;
}
void sprawdz_dlugosc(int *tab) {
while (*tab <8 || *tab>22) {
printf ("\nDługość tablicy [8-22] elementów");
wprowadz_dlugosc(&*tab);
}
}
void losuj_liczby(int *tab)
{
int i;
for(i=0; i<dlugosc_tab; i++)
tab[i]= -5 + rand()%11;
return;
}
void wyswietl_tab(int *tab){
int i;
for(i=0; i<dlugosc_tab; i++)
printf (" %d,",tab[i]);
return;
}