From 6e014ca5ce263e96549236b5bf4f2379467b9e2b Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 27 Sep 2021 13:13:17 +0300 Subject: setting up git on old project --- input.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 input.c (limited to 'input.c') diff --git a/input.c b/input.c new file mode 100644 index 0000000..bf4dfbd --- /dev/null +++ b/input.c @@ -0,0 +1,60 @@ +#ifndef DET_INPUT_C +#define DET_INPUT_C DET_INPUT_C +//how many digits is a number from -n is allowed to have +#define MAX_DIGITS 100 +#include +#include +#include"gmp.h" +#include + + + +void input_det(FILE* input,mpq_t ***det,size_t *size) +{ + + + fscanf(input,"%zu",size); + (*det)=malloc(sizeof(mpq_t*)*(*size) + sizeof(mpq_t)*(*size)*(*size)); + size_t i,j; + + for(i=0;i<(*size);++i) + { + (*det)[i]=((mpq_t*)(((u_int8_t*)(*det)) + sizeof(mpq_t*)*(*size) + sizeof(mpq_t)*(*size)*i)); + for(j=0;j<(*size);++j) + { + + mpq_init((*det)[i][j]); + gmp_fscanf(input,"%Qi",(*det)[i][j]); + } + } +} +/* + * places a randomised matrix in det + * whose digits are 1 to MAX_DIGITS long + * + */ +void random_table(mpq_t ***det,size_t size) +{ + (*det)=malloc(sizeof(mpq_t*)*size + sizeof(mpq_t)*size*size); + size_t i,j; + size_t sz; + char *number;//we don't want a stack overflow so it goes on the heap + number = malloc(sizeof(char)*MAX_DIGITS+1); + srand(time(NULL)); + + for(i=0;i0;number[sz]=rand()%10+'0',--sz); + number[0]=rand()%9 + '1'; + + mpq_init((*det)[i][j]); + gmp_sscanf(number,"%Qi",(*det)[i][j]); + } + } +} +#endif//#ifndef DET_INPUT_C -- cgit v1.2.3