Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 15 additions & 129 deletions Sequences.c
Original file line number Diff line number Diff line change
@@ -1,137 +1,23 @@
<<<<<<< HEAD
//
// Sequences.c
//
//
// Created by Cesar Angeles on 07/09/2020.
//

#include <stdio.h>
#include <stdlib.h>

#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 <stdio.h>

#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
4 changes: 3 additions & 1 deletion Sequences.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Sequences.h
//
//
//
// Created by Cesar Angeles on 07/09/2020.
//
Expand All @@ -15,6 +15,8 @@
#else
#define EXTERN extern
#endif
#define FILAS 25
#define COL 4


/* Sequences.h -- Function prototypes */
Expand Down
78 changes: 78 additions & 0 deletions diagnostic.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

/* 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;
}
128 changes: 13 additions & 115 deletions files.c
Original file line number Diff line number Diff line change
@@ -1,122 +1,20 @@
<<<<<<< HEAD
//
// files.c
//
//
// Created by Cesar Angeles on 07/09/2020.
//

#include <stdio.h>

#define files_IMPORT
#include "files.h"



#include <stdlib.h>


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 <stdio.h>

#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
Loading