diff --git a/120093298_445616363077697_6481669934674483867_n.png b/120093298_445616363077697_6481669934674483867_n.png new file mode 100644 index 0000000..6641780 Binary files /dev/null and b/120093298_445616363077697_6481669934674483867_n.png differ diff --git a/Sequences.c b/Sequences.c index 4ef9c72..f5014b7 100644 --- a/Sequences.c +++ b/Sequences.c @@ -1,137 +1,23 @@ -<<<<<<< HEAD -// -// Sequences.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - #include -#include - -#define Sequences_IMPORT -#include "Sequences.h" - - +//fibonacci secuencial long long int Sequences_sfibo(long long int n){ - long long int sequence_1 = 0, sequence_2 = 1, temp = 0; - int index = 0; - - for (index = 0; index < n; index ++){ - - temp = sequence_2; - sequence_2 = sequence_2 + sequence_1; - sequence_1 = temp; - - } - (n<=0) ? sequence_2 = 0 : (sequence_2 = sequence_1); - - return sequence_2; - + int actual, ant1 = 1, ant2 = 1,i; + if ((n == 0) || (n == 1)) { + actual = 1; + } + else{ + for (i=2; i<=n; i++) { + actual = ant1 + ant2; + ant2 = ant1; + ant1 = actual; + } + } + return actual; } - - long long int Sequences_rfibo(long long int n){ - - if (n == 1){ - return 1; - } - if(n > 1){ - return Sequences_rfibo(n - 1) + Sequences_rfibo(n - 2); - }else{ - return 0; - } - -} -||||||| f46ea0f -======= -// -// Sequences.h -// -// -// Created by Cesar Angeles on 07/09/2020. -// - -#ifndef Sequences_h -#define Sequences_h - -#include - -#ifdef Sequences_IMPORT - #define EXTERN -#else - #define EXTERN extern -#endif - - -/* Sequences.h -- Function prototypes */ - -/** - * Returns the value of the fibonacci sequence at index n calculated sequentially - * @param - * n (long long int): - * Index of the fibonacci sequence - * @return long long int value -*/ - -/*long long int Sequences_sfibo(long long int n) { - int prev_number = 0, next_number = 1; - n = prev_number; - prev_number = next_number; - next_number = next_number + n; + if (n < 2) return n; -}*/ - -long long int Sequences_sfibo(long long int n){ - long long int prev_number = 0, next_number = 1, fibonacci_number = 0; - int index = 0; - - for (index = 0; index < n; index ++){ - fibonacci_number = prev_number; - prev_number = next_number; - next_number = next_number + fibonacci_number; - return fibonacci_number; - } - +return Sequences_rfibo(n - 1) + Sequences_rfibo(n - 2); } - - -/** - * Returns the value of the fibonacci sequence at index n calculated recursively - * @param - * n (long long int): - * Index of the fibonacci sequence - * @return long long int value -*/ - -/*long long int Sequences_rfibo(long long int n) { - if(n == 0) { - return 0; - } - else if(n == 1) { - return 1; - } - else { - return(recursive_fib(n - 1) + recursive_fib(n - 2)); - } -}*/ - -long long int Sequences_rfibo(long long int number){ - if (number == 0){ - return 0; - } - else if(number == 1){ - return 1; - } - else{ - return Sequences_rfibo(number - 1) + Sequences_rfibo(number - 2); - } -} - - -#undef Sequences_IMPORT -#undef EXTERN -#endif /* Sequences_h */ ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/Sequences.h b/Sequences.h index dac8ae0..89846f3 100644 --- a/Sequences.h +++ b/Sequences.h @@ -1,6 +1,6 @@ // // Sequences.h -// +// // // Created by Cesar Angeles on 07/09/2020. // @@ -15,6 +15,8 @@ #else #define EXTERN extern #endif +#define FILAS 25 +#define COL 4 /* Sequences.h -- Function prototypes */ diff --git a/diagnostic.c b/diagnostic.c new file mode 100644 index 0000000..435854c --- /dev/null +++ b/diagnostic.c @@ -0,0 +1,78 @@ +// +// Sequences.c +// +// +// Created by Alejandro Solorzano, Sergio Javier 08/09/2020 +// +/** +* Our sample program. +* @copyright 2008 by TDA +* @license as you wish +* @author Alejandro Solorzano, Sergio Javier +* @version 2020-08-09 +* @file +*/ + + +/* Include standard headers: */ +#include +#include +#include +#include + +/* Include modules header we directly invoke here: */ +#include "Sequences.h" +#include "files.h" + + + +int main(int argc, char **argv) +{ + /* Initialize modules: */ + long long int n = 0; + int index = 0; + clock_t start,stop; + double time = 0; + FILE *p = NULL; + long double buffer [FILAS][COL] = {0}; + p=file_new("test.dat","wt"); + + + + for (size_t i = 0; i < FILAS; i++) { + + + start = clock (); + for (index = 0; index <= 100; index++) { + Sequences_rfibo(i); + } + stop = clock (); + + + time = ((double)(stop-start))/CLOCKS_PER_SEC/100.0; + buffer [i][0] = i; + buffer [i][1] = time*1e3; + printf("Recursivo %f\t",time); + + start = clock (); + + for (index = 0; index <= 100; index++) { + Sequences_sfibo(i); + } + stop = clock (); + + + time = ((double)(stop-start))/CLOCKS_PER_SEC/100.0; + buffer [i][2] = time*1e9; + printf("Secuencial %f\n",time); + + } + + + + file_num_write(p, COL, buffer, FILAS); + fclose (p); + + + return 0; +} diff --git a/files.c b/files.c index 96d0a32..3fe87da 100644 --- a/files.c +++ b/files.c @@ -1,122 +1,20 @@ -<<<<<<< HEAD -// -// files.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - #include - -#define files_IMPORT -#include "files.h" - - - +#include FILE * file_new(char *name, char *mode){ - FILE * my_file = NULL; - - my_file = fopen(name, mode); - - if (my_file == NULL){ - puts("FILE OPEN ERROR"); - return NULL; - }else - return my_file; + FILE *fp; + fp = fopen (name, mode); + return fp; } - -void file_num_write(FILE * file,size_t columns, long double buff[][columns], size_t rows){ - size_t row, column = 0; - - for(row = 0; row < rows; row ++){ - for(column = 0; column < columns; column ++){ - fprintf(file, "%Lf\t", buff[row][column]); - } - fprintf(file, "\n"); - } +void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows){ + int i,o; + for (i = 0 ; i < rows ; i++) + { + fprintf(file, "%Lf \t",buff[i][0]); + fprintf(file, "%Lf \t",buff[i][1]); + fprintf(file, "%Lf \t",buff[i][2]); + fprintf (file, "\n"); + } } -||||||| f46ea0f -======= -// -// files.h -// -// -// Created by Cesar Angeles on 07/09/2020. -// - -#ifndef files_h -#define files_h - -#include - -#ifdef files_IMPORT - #define EXTERN -#else - #define EXTERN extern -#endif - - -/* files.h -- Function prototypes */ - -/** - * Instanciates a new file pointer identified via its name and mode. - * @param - * name (char *): - * Name of the file - * mode (char *): - * Mode of file to be opened {r, rb, a, ab, w, wb} - * - * @return FILE * opened_file. -*/ - -FILE * file_new(char *name, char *mode){ - FILE * my_file = NULL; - - my_file = fopen(name, mode); - - if (my_file == NULL){ - puts("FILE OPEN ERROR"); - return NULL; - } - else - return my_file; -} - - - -/** - * Writes a bidimensional buffer array into a file. - * @param - * file (FILE *): - * Storage file - * columns (size_t ): - * length of the buffer array - * buff [ ][columns] (long double): - * RAM matrix - * rows (size_t): - * width of the storage buffer - * - * @return void. -*/ - -void file_num_write(FILE * file, size_t columns, long double buff[][columns], size_t rows) { - size_t row, column; - - for(row = 0; row < rows; row ++){ - for(column = 0; column < columns; column ++){ - fprintf(file, "%Lf\t", buff[row][column]); - } - fprintf(file, "\n"); - } -} - -#undef files_IMPORT -#undef EXTERN - - - -#endif /* files_h */ ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/files.h b/files.h index 254089b..9a227c8 100644 --- a/files.h +++ b/files.h @@ -1,6 +1,6 @@ // // files.h -// +// // // Created by Cesar Angeles on 07/09/2020. // @@ -9,6 +9,7 @@ #define files_h #include +#include #ifdef files_IMPORT #define EXTERN @@ -56,7 +57,3 @@ EXTERN void file_num_write(FILE * file, size_t columns, long double buff[] [colu #endif /* files_h */ - - -/*ietartivos en milisegundos -recursivos en segundos*/ \ No newline at end of file diff --git a/test.dat b/test.dat new file mode 100644 index 0000000..646c10a --- /dev/null +++ b/test.dat @@ -0,0 +1,25 @@ +0.000000 0.001000 0.003000 +1.000000 0.001000 0.002000 +2.000000 0.002000 0.001000 +3.000000 0.002000 0.002000 +4.000000 0.002000 0.002000 +5.000000 0.002000 0.001000 +6.000000 0.001000 0.001000 +7.000000 0.001000 0.000000 +8.000000 0.001000 0.001000 +9.000000 0.002000 0.001000 +10.000000 0.002000 0.001000 +11.000000 0.002000 0.001000 +12.000000 0.003000 0.001000 +13.000000 0.004000 0.001000 +14.000000 0.005000 0.001000 +15.000000 0.007000 0.001000 +16.000000 0.011000 0.001000 +17.000000 0.017000 0.001000 +18.000000 0.027000 0.001000 +19.000000 0.043000 0.001000 +20.000000 0.069000 0.001000 +21.000000 0.112000 0.001000 +22.000000 0.180000 0.001000 +23.000000 0.290000 0.001000 +24.000000 0.469000 0.001000