diff --git a/FIBONACCI.txt b/FIBONACCI.txt new file mode 100644 index 0000000..737558c --- /dev/null +++ b/FIBONACCI.txt @@ -0,0 +1,124 @@ +nan 0.000000 nan 0.000000 +0.000000 0.000000 -nan -nan +-nan nan -nan -nan +-nan -nan 0.000000 -nan +-nan nan nan 0.000000 +0.000000 nan nan -nan +-nan 0.000000 nan 0.000000 +0.000000 nan nan -nan +-nan -nan -nan -nan +-nan 0.000000 0.000000 0.000000 +0.000000 -nan nan nan +nan 0.000000 -nan 0.000000 +0.000000 nan 0.000000 0.000000 +0.000000 0.000000 nan -nan +-nan -nan nan 0.000000 +0.000000 -nan nan -nan +-nan 0.000000 nan nan +nan nan 0.000000 nan +nan 0.000000 0.000000 -nan +-nan -nan nan -nan +-nan -nan nan 0.000000 +0.000000 -nan 0.000000 nan +nan 0.000000 nan 0.000000 +0.000000 -nan 0.000000 24.000000 +24.000000 452572026218753208844167144505637852943351061397257105077256453941045440125732158362390419452647815896575356914988496831423875763173658276032064928495888158934266945072721543400406981439504343937575212190700025842334521011542278991532949380635236230019915787706192923305457425311020377859717765818695603240597135054027204514527614342290479969106760014711714815786329843884784218930992584975008594539025905302147563125399181585876435388050627122760338974664716776832579049090307571225018283187956556342847532842813846796929957482104955834984571008885502626555485220283664337996408088978171032567174671536877114330153762295496290472513318734908478145193481792775659750687991913392596350634728190137707740043354138798627872205393665716875202777953915987620473375777249015885888683541925623369633268956336947743117133731745327205783607292528819884120535555866796858406307943277696836049651108487006418289285696696388593399697009889540032090771295971092802135811413608329240563865888293540450329903295727639816149831232202224137701693734402139058455502951760103926199393624807925591069048289051329635512828835082623777950234330247996939521627538399248221508283954885031759077451478559615916598542341427722045004105135372906505386222719424448439832212179139083905836744329544885207645078316551989240542682660186624500923903895977147074757184384444846323261240016326888669178080932217387698226378783373583514332298201757346679675721742253351888861374984153679872737292735907442933877626760244230453135960380093141066159556287518999594948429577309610018972878446929439328790724871775054361649445006345418819559536789979331662069302441639121051376578235752998428908766309156869362283239386639409799846604090652668572294150683518182359845957460443619754727611592303561453051817724782648571699355835126885216375614390432883373178133875049895463841429632074126575195617068116951894086637302063879828146883247486876099247531931994545389040465897991321408460364489213953623023903797844707502867549484632657208903348394529747730514916760415265132727309375205761517428757279186437010388961039044833284797069294145493459807585869444083888991883150052900923516707408109606346314651049576717107439532391378438325565704244813246639571180565166269611849197287948275647550625473208959822102567582518239616496870459649025980010138130134160096818578226057597608521055165122872182928463040347351942369891059066680919083967307888276318365343090518755687601448579753024005809991393619990575377878701845466805570223777039085866153737403312659763175579149187035839036894553056673150667895008311344002329086314134385072336068947775569430241913986978645358572101777159497648456145846525534395067832644430843203556616914081419571909243608045449488758182943292464479323365091074286383970854936087733744586449515400689787839147477392470260404934930982961142378485159405500290986793261479674687277866085536111866054124179117395821067531216185799519234449744192650266235139099018886715255342837680802676787838821123000845276842561487575848928707142610457022080452179103309513215427235771555818104566268678929962861325959612623978164053343284141440656074705464660630129761461667066603754225664.000000 0.000020 -nan +-nan nan -nan nan +nan nan nan nan +nan nan nan 0.000000 +0.000000 nan 0.000000 nan +nan nan 0.000000 nan +nan nan nan -nan +-nan -nan -nan -nan +-nan -nan -nan -nan +-nan -nan -nan -nan +-nan -nan -nan -nan +-nan -nan -nan nan +nan nan nan nan +nan nan nan nan +nan nan nan nan +nan nan nan nan +nan nan nan nan +nan nan nan nan +nan 0.000000 -nan 3488803814779835714253063262064496857247810870822702038882467476458739080378839031647307618214035672167625345295100829878490218774613169421168419431860427861510407098544113393688881780011599400941588547039365985349279128748796605525630426402255093080516826084569044038120376475235090200237078841107232704654540411117364706824008152330666743969342159672223243313536711620108765295530963017002997679841317439329255903931385693134145558380236424288790523164797918812138664654617867841664079324367186858761472112058459320520190358134280892664543517995852588076316663395932799330078067414144065745775617313948499043491529351312236485687886683872448288755411003671278051814054790266640106160601444176694428649961735303147647238842163395694246743347699580753765291135010112415771868547433609798338677732024667739967016888601051679741493440911445979410437269765886462798968433199048019638295249111203170674425854757494443804016808648535484094313110550982004828664900546649107750895828084460725696601119874284815608320247254399998270489212382448033702205400911626197279284222893648653633161343185877190797899197130466652766827948585820486510175919513501420270807834623398080156103734371211257616758090721624471058077347650791994577414992381380515994926371125754249247420890376877828899433595504328405978597928187136709689195779921743318943485873887159892221919050736042388221413169122669206732000283242204244454528408570576309552616179796186452601175956231621144540966268283459381052127722173977351451477835823033563601995460836185081661200790076442834145812275344141241660696501029806130302665245589661708773949839366840371880476585504163825583738724667312629006974375167734296782763121190064358746425345899131538401571565437711583683396118879950021936754251445944467047604235928415556231020334309454848355437250151612719090248642812766158694951526373698819415588083486221679169957455359149285091055457210266644603203629390144410128506399344598770611853989253939953926599439734173649079872491844784361941780044092722509579129999377705911142634636733792834000128913081015686780404139923769290019992592716218109973245793540366874624723516161596603845952915033334713653258107512634942245746811405333551338743654894143120620391128943880358892721862673906960280219012560332180488445360772495740267751559785695663814675896929232212320878576984191185990491195256042037837256967395075197803926824985928117400516750785658547933173347497613017893777043231723364514720934737840508747426437392839169740320255306029994856015209723833182538034099201089635179476656538817758361316119950675911593321311966907200416587959457836807658342141371763098783038365949322566518005651565902737882390026120807338777098971066368001426436143879061708548253370209861595938487453313077716531099497081695317451092762814161560513879309604792575234541627265795628869625709098525461196101391046990840930624230830476387958621776176649014622671948783832806994654766890240679946857321272755613441557194097841563632803711704713026599581491581516209005617762574189609101716866758699631319156828791711547003862723478787339995444723890972994176646733369933348232884196133177424210116860922265473648686083314656468952202266216073211394459697810065208080608876009458671456295818513187086307457934136178907580163682917805294813831701631692332129533831596483353584972083791572446358754429507055087601132872401649351603999861938381305055272823325572550750792642340805626809218544798701677886523092783461376367565098153729995712770802513664399320194078136934010535255862813140982997306427186389062049852654831706365608047884518747186927826255184227443096637683451932447690379181373428359068514770233653177876972962218777912347087518599722564975829771846882561317958251880907804897458279313726276574955058373514247000199697009800014255996199049973640791999647400244337750558935438201344225612214957955566397982948797068230955070031726557748770839995741981929644888958392713880579457590824310875096441446680641729387858130078847704906325589937274356207713556481109411095023217529784112434135633837255711644811592963259637998820400199278300432508340989428672244816335128947615361961703769838381713889822641776307133054321135467343183737595560303810578235570809106546700786693209055914224180927997841908531051871610779536494400344356736824453478804093655287152987370103136535524957989880080477109620642361869858308767026094538752.000000 +3488803814779835714253063262064496857247810870822702038882467476458739080378839031647307618214035672167625345295100829878490218774613169421168419431860427861510407098544113393688881780011599400941588547039365985349279128748796605525630426402255093080516826084569044038120376475235090200237078841107232704654540411117364706824008152330666743969342159672223243313536711620108765295530963017002997679841317439329255903931385693134145558380236424288790523164797918812138664654617867841664079324367186858761472112058459320520190358134280892664543517995852588076316663395932799330078067414144065745775617313948499043491529351312236485687886683872448288755411003671278051814054790266640106160601444176694428649961735303147647238842163395694246743347699580753765291135010112415771868547433609798338677732024667739967016888601051679741493440911445979410437269765886462798968433199048019638295249111203170674425854757494443804016808648535484094313110550982004828664900546649107750895828084460725696601119874284815608320247254399998270489212382448033702205400911626197279284222893648653633161343185877190797899197130466652766827948585820486510175919513501420270807834623398080156103734371211257616758090721624471058077347650791994577414992381380515994926371125754249247420890376877828899433595504328405978597928187136709689195779921743318943485873887159892221919050736042388221413169122669206732000283242204244454528408570576309552616179796186452601175956231621144540966268283459381052127722173977351451477835823033563601995460836185081661200790076442834145812275344141241660696501029806130302665245589661708773949839366840371880476585504163825583738724667312629006974375167734296782763121190064358746425345899131538401571565437711583683396118879950021936754251445944467047604235928415556231020334309454848355437250151612719090248642812766158694951526373698819415588083486221679169957455359149285091055457210266644603203629390144410128506399344598770611853989253939953926599439734173649079872491844784361941780044092722509579129999377705911142634636733792834000128913081015686780404139923769290019992592716218109973245793540366874624723516161596603845952915033334713653258107512634942245746811405333551338743654894143120620391128943880358892721862673906960280219012560332180488445360772495740267751559785695663814675896929232212320878576984191185990491195256042037837256967395075197803926824985928117400516750785658547933173347497613017893777043231723364514720934737840508747426437392839169740320255306029994856015209723833182538034099201089635179476656538817758361316119950675911593321311966907200416587959457836807658342141371763098783038365949322566518005651565902737882390026120807338777098971066368001426436143879061708548253370209861595938487453313077716531099497081695317451092762814161560513879309604792575234541627265795628869625709098525461196101391046990840930624230830476387958621776176649014622671948783832806994654766890240679946857321272755613441557194097841563632803711704713026599581491581516209005617762574189609101716866758699631319156828791711547003862723478787339995444723890972994176646733369933348232884196133177424210116860922265473648686083314656468952202266216073211394459697810065208080608876009458671456295818513187086307457934136178907580163682917805294813831701631692332129533831596483353584972083791572446358754429507055087601132872401649351603999861938381305055272823325572550750792642340805626809218544798701677886523092783461376367565098153729995712770802513664399320194078136934010535255862813140982997306427186389062049852654831706365608047884518747186927826255184227443096637683451932447690379181373428359068514770233653177876972962218777912347087518599722564975829771846882561317958251880907804897458279313726276574955058373514247000199697009800014255996199049973640791999647400244337750558935438201344225612214957955566397982948797068230955070031726557748770839995741981929644888958392713880579457590824310875096441446680641729387858130078847704906325589937274356207713556481109411095023217529784112434135633837255711644811592963259637998820400199278300432508340989428672244816335128947615361961703769838381713889822641776307133054321135467343183737595560303810578235570809106546700786693209055914224180927997841908531051871610779536494400344356736824453478804093655287152987370103136535524957989880080477109620642361869858308767026094538752.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0.000000 +0.000000 0.000000 0.000000 0 \ No newline at end of file diff --git a/FIBO_TIME.dat b/FIBO_TIME.dat deleted file mode 100644 index 647702c..0000000 --- a/FIBO_TIME.dat +++ /dev/null @@ -1,61 +0,0 @@ -<<<<<<< HEAD -0.000000 0.000000 0.000010 -1.000000 0.000000 0.000000 -2.000000 0.000000 0.000000 -3.000000 0.000000 0.000010 -4.000000 0.000000 0.000020 -5.000000 0.000000 0.000020 -6.000000 0.000000 0.000020 -7.000000 0.000000 0.000030 -8.000000 0.000000 0.000020 -9.000000 0.000000 0.000020 -10.000000 0.000000 0.000030 -11.000000 0.000001 0.000040 -12.000000 0.000001 0.000050 -13.000000 0.000002 0.000040 -14.000000 0.000003 0.000040 -15.000000 0.000005 0.000040 -16.000000 0.000008 0.000060 -17.000000 0.000013 0.000050 -18.000000 0.000020 0.000050 -19.000000 0.000032 0.000050 -20.000000 0.000052 0.000060 -21.000000 0.000082 0.000060 -22.000000 0.000130 0.000060 -23.000000 0.000211 0.000050 -24.000000 0.000341 0.000060 -25.000000 0.000569 0.000060 -||||||| f46ea0f -======= -0.000000 0.000000 0.000000 -1.000000 0.000000 0.000000 -2.000000 0.000000 0.000000 -3.000000 0.000000 0.000000 -4.000000 0.000000 0.000000 -5.000000 0.000000 0.000000 -6.000000 0.000000 0.000000 -7.000000 0.000000 0.000000 -8.000000 0.000000 0.000000 -9.000000 0.000000 0.000000 -10.000000 0.000000 0.000000 -11.000000 0.000000 0.000000 -12.000000 0.000000 0.000000 -13.000000 0.000000 0.000000 -14.000000 0.000000 0.000000 -15.000000 0.000000 0.000000 -16.000000 0.000000 0.000000 -17.000000 0.000000 0.000000 -18.000000 0.000156 0.000000 -19.000000 0.000000 0.000000 -20.000000 0.000156 0.000000 -21.000000 0.000313 0.000000 -22.000000 0.000313 0.000000 -23.000000 0.000625 0.000000 -24.000000 0.000937 0.000000 -25.000000 0.001563 0.000000 -26.000000 0.002344 0.000000 -27.000000 0.003750 0.000000 -28.000000 0.006250 0.000000 -29.000000 0.009687 0.000000 -30.000000 0.015938 0.000000 ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f254c03 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +fibo.out: main.c Sequences.c files.c + gcc -g -o fibo.out main.c Sequences.c files.c + +main.o: main.c + gcc -g -c main.c + +Sequences.o: Sequences.c + gcc -g -c Sequences.c + +files.o: files.c + gcc -g -c files.c + +clean: + rm *.o diff --git a/Sequences.c b/Sequences.c index 4ef9c72..ae7e2ae 100644 --- a/Sequences.c +++ b/Sequences.c @@ -1,137 +1,30 @@ -<<<<<<< HEAD -// -// Sequences.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - #include -#include - -#define Sequences_IMPORT #include "Sequences.h" - - -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; - -} - - - -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; - 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; - } - +long long int Sequences_sfibo(long long int n) +{ + long long int t1 = 0, t2 = 1, sig; + int i; + + for (i = 1; i <= n; ++i) + { + sig = t1 + t2; + t1 = t2; + t2 = sig; + } + return sig; } - -/** - * 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); - } +long long int Sequences_rfibo(long long int n) +{ + if (n>2) + return Sequences_rfibo(n-1) + Sequences_rfibo(n-2); + else if (n==2) + return 1; + else if (n==1) + return 1; + else if (n==0) + return 0; + else + return -1; } - - -#undef Sequences_IMPORT -#undef EXTERN -#endif /* Sequences_h */ ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/fibo.out b/fibo.out new file mode 100644 index 0000000..3246e4a Binary files /dev/null and b/fibo.out differ diff --git a/files.c b/files.c index 96d0a32..87bddf1 100644 --- a/files.c +++ b/files.c @@ -1,122 +1,29 @@ -<<<<<<< HEAD -// -// files.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - #include - -#define files_IMPORT #include "files.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; -} - - -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"); +FILE * file_new(char *name, char *mode) +{ + FILE *fp = NULL; + fp = fopen(name, mode); + if (fp == NULL){ + puts("FILE OPEN ERROR"); + return NULL; } + else + return fp; } -||||||| 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"); +void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows) +{ + size_t i, j; + for(i = 0; i <= rows; i++) + { + for(j = 0; j <= columns; j++) + { + fprintf(file, "%Lf \t", buff[i][j]); } + fprintf(file,"\n"); + } + return; } - -#undef files_IMPORT -#undef EXTERN - - - -#endif /* files_h */ ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/files.h b/files.h index 254089b..7ddc38b 100644 --- a/files.h +++ b/files.h @@ -56,7 +56,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/main.c b/main.c new file mode 100644 index 0000000..0f8522e --- /dev/null +++ b/main.c @@ -0,0 +1,38 @@ +#include +#include + +#include "files.h" +#include "Sequences.h" + +int main(void) +{ + int n = 24, i; + FILE * new; + long double buffer[n][3]; + double cpu_time = 0; + clock_t start, stop; + new = file_new("FIBONACCI.txt", "w"); + + for(i = 1; i<=n; i++) + { + start = clock(); + Sequences_rfibo(n); + stop = clock(); + cpu_time = ((double)(stop-start))/CLOCKS_PER_SEC / 100; + buffer[n][0] = n; + buffer[n][1] = cpu_time; + printf("Recursiva: %f\n", cpu_time); + + start = clock(); + Sequences_sfibo(n); + stop = clock(); + cpu_time = ((double)(stop-start))/CLOCKS_PER_SEC / 100; + buffer[n][0] = n; + buffer[n][2] = cpu_time*1000; + printf("Secuencial: %f\n", cpu_time*1000); + } + + file_num_write(new, 3, buffer, n); + fclose(new); + +} diff --git a/makefile b/makefile index 1fabd67..40834b0 100644 --- a/makefile +++ b/makefile @@ -1,13 +1,14 @@ -CC = gcc -CFLAGS = -I -Wall -DEPS = Sequences.h files.h time_test_fibo.h -OBJ = time_test_fibo.o Sequences.o files.o +fibo.out: main.c Sequences.c files.c + gcc -g -o fibo.out main.c Sequences.c files.c -%.o : %.c $(DEPS) - $(CC) -c -o $@ $< $(CFLAGS) +main.o: main.c + gcc -g -c main.c -time_test_fibo: $(OBJ) - $(CC) -o $@ $^ $(CFLAGS) +Sequences.o: Sequences.c + gcc -g -c Sequences.c + +files.o: files.c + gcc -g -c files.c clean: rm *.o diff --git a/time_test b/time_test deleted file mode 100755 index d650812..0000000 Binary files a/time_test and /dev/null differ diff --git a/time_test_fibo b/time_test_fibo deleted file mode 100755 index 99f4fe7..0000000 Binary files a/time_test_fibo and /dev/null differ diff --git a/time_test_fibo.c b/time_test_fibo.c deleted file mode 100644 index 75c202b..0000000 --- a/time_test_fibo.c +++ /dev/null @@ -1,130 +0,0 @@ -<<<<<<< HEAD -// -// time_test_fibo.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - - - -#include -#include - - - -#include "Sequences.h" -#include "files.h" -#include "time_test_fibo.h" - -int main(void){ - - long long int value = 0; - int index = 0; - clock_t start, stop; - double cpu_time = 0; - double mean = 0; - FILE * record = NULL; - long double buffer[OBSERVATIONS][VALUES] = {0}; - size_t obs = 0; - - record = file_new("FIBO_TIME.dat","w"); - - //puts("Enter n fibo value:"); - //scanf("%lld", &value); - - printf("%lld\t", value); - - for (obs = 0; obs < OBSERVATIONS; obs ++){ - printf("%zu\n",obs); - - - start = clock(); - for (index = 0; index <= STATISTIC; index ++){ - Sequences_rfibo(obs); - } - stop = clock(); - - cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; - buffer[obs][INDEX] = obs; - buffer[obs][RECURSIVE] = cpu_time; - printf("Recursive Fibo time %f s\t", cpu_time); - - start = clock(); - for (index = 0; index <= STATISTIC; index ++){ - Sequences_sfibo(obs); - } - stop = clock(); - - cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; - buffer[obs][ITERATIVE] = cpu_time*1e3; - printf("Sequential Fibo time %f ms\n", cpu_time*1e3); - } - - file_num_write(record, VALUES, buffer, OBSERVATIONS); - fclose(record); - -} -||||||| f46ea0f -======= -// -// time_test_fibo.c -// -// -// Created by Cesar Angeles on 07/09/2020. -// - - - -#include -#include - - - -#include "Sequences.h" -#include "files.h" -#include "time_test_fibo.h" - -int main(void){ - - long long int value = 0; - int index = 0; - clock_t start, stop; - double cpu_time = 0; - double mean = 0; - FILE * record = NULL; - long double buffer[OBSERVATIONS][VALUES] = {0}; - size_t obs = 0; - - record = file_new("FIBO_TIME.dat","w"); - - for(obs = 0; obs < OBSERVATIONS; obs ++) { - printf("%zu\n", obs); - - start = clock(); - for (index = 0; index <= STATISTIC; index ++){ - Sequences_rfibo(obs); - } - stop = clock(); - - cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; - buffer[obs][INDEX] = obs; - buffer[obs][RECURSIVE] = cpu_time; - printf("Recursive Fibo time %f s\t", cpu_time); - - start = clock(); - for (index = 0; index <= STATISTIC; index ++){ - Sequences_sfibo(obs); - } - stop = clock(); - - cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; - buffer[obs][ITERATIVE] = cpu_time*1e3; - printf("Sequential Fibo time %f ms\n", cpu_time*1e3); - } - - file_num_write(record, VALUES, buffer, OBSERVATIONS); - fclose(record); - -} ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/time_test_fibo.h b/time_test_fibo.h deleted file mode 100644 index 42699e6..0000000 --- a/time_test_fibo.h +++ /dev/null @@ -1,52 +0,0 @@ -<<<<<<< HEAD -// -// time_test_fibo.h -// -// -// Created by Cesar Angeles on 07/09/2020. -// - -#ifndef time_test_fibo_h -#define time_test_fibo_h - -#include -#include "files.h" - -#define STATISTIC 100.0 -#define OBSERVATIONS 26 -#define VALUES 3 - -typedef enum{ - INDEX, - RECURSIVE, - ITERATIVE -}TYPE; - -#endif /* time_test_fibo_h */ -||||||| f46ea0f -======= -// -// time_test_fibo.h -// -// -// Created by Cesar Angeles on 07/09/2020. -// - -#ifndef time_test_fibo_h -#define time_test_fibo_h - -#include -#include "files.h" - -#define STATISTIC 100.0 -#define OBSERVATIONS 31 -#define VALUES 3 - -typedef enum{ - INDEX, - RECURSIVE, - ITERATIVE -}TYPE; - -#endif /* time_test_fibo_h */ ->>>>>>> e94102e9b652f269c770d77c8267559b161b52fd