{"id":57753,"date":"2022-12-29T03:01:43","date_gmt":"2022-12-28T17:01:43","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=57753"},"modified":"2022-12-27T15:01:30","modified_gmt":"2022-12-27T05:01:30","slug":"c-recursion-fibonacci-series-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-fibonacci-series-tutorial\/","title":{"rendered":"C++ Recursion Fibonacci Series Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/fibonacci_series.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C++ Recursion Fibonacci Series Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/fibonacci_series.jpg\" title=\"C++ Recursion Fibonacci Series Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C++ Recursion Fibonacci Series Tutorial<\/p><\/div>\n<p>We&#8217;re revisiting the Fibonacci Series code of <a title='C Recursion Find Revisit Tutorial' href='#crfrt'>C Recursion Find Revisit Tutorial<\/a> and compiling it, plus some extended functionality, via the g++ c++ compiler on a macOS command line, as per &#8230;<\/p>\n<p><code><br \/>\ng++ fibonacci_series.cpp -o fibonacci_series.out<br \/>\n<\/code><\/p>\n<p> &#8230; regarding <a target=_blank title='fibonacci_series.cpp' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/main.cpp--GETME\">the changed<\/a> <a target=_blank title='fibonacci_series.cpp' href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/main.cpp--GETME\">fibonacci_series.cpp<\/a> code.  Today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/fibonacci_series.jpg\" title=\"Click picture\">tutorial picture<\/a> displays the execution run involving the <font color=blue>interactive input<\/font> as per &#8230;<\/p>\n<p><code style='font-size:6px;font-family:Courier New;font-weight:bold;'><br \/>\n<font color=blue>.\/fibonacci_series.out<\/font><br \/>\nHow many numbers are there in your fibonacci sequence (-ve for in a row): <font color=blue>23<\/font><br \/>\n0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657<br \/>\n<br \/>\n                                                                         0, 1<br \/>\n 0 + 1 = 1<br \/>\n                                                                       0, 1, 1<br \/>\n 0 + 1 = 1<br \/>\n                                                                     0, 1, 1, 2<br \/>\n 1 + 1 = 2<br \/>\n                                                                   0, 1, 1, 2, 3<br \/>\n 1 + 2 = 3<br \/>\n                                                                 0, 1, 1, 2, 3, 5<br \/>\n 2 + 3 = 5<br \/>\n                                                               0, 1, 1, 2, 3, 5, 8<br \/>\n 3 + 5 = 8<br \/>\n                                                             0, 1, 1, 2, 3, 5, 8, 13<br \/>\n 5 + 8 = 13<br \/>\n                                                           0, 1, 1, 2, 3, 5, 8, 13, 21<br \/>\n 8 + 13 = 21<br \/>\n                                                         0, 1, 1, 2, 3, 5, 8, 13, 21, 34<br \/>\n 13 + 21 = 34<br \/>\n                                                       0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55<br \/>\n 21 + 34 = 55<br \/>\n                                                     0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89<br \/>\n 34 + 55 = 89<br \/>\n                                                   0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144<br \/>\n 55 + 89 = 144<br \/>\n                                                 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233<br \/>\n 89 + 144 = 233<br \/>\n                                               0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377<br \/>\n 144 + 233 = 377<br \/>\n                                             0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610<br \/>\n 233 + 377 = 610<br \/>\n                                           0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987<br \/>\n 377 + 610 = 987<br \/>\n                                         0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597<br \/>\n 610 + 987 = 1597<br \/>\n                                       0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584<br \/>\n 987 + 1597 = 2584<br \/>\n                                     0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181<br \/>\n 1597 + 2584 = 4181<br \/>\n                                   0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765<br \/>\n 2584 + 4181 = 6765<br \/>\n                                 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946<br \/>\n 4181 + 6765 = 10946<br \/>\n                               0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711<br \/>\n 6765 + 10946 = 17711<br \/>\n                             0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657<br \/>\n 10946 + 17711 = 28657<br \/>\n<\/code><\/p>\n<p> &#8230; using the C++ command line code &#8230;<\/p>\n<p><code><br \/>\n\/\/   Fibonacci sequence<br \/>\n\/\/   Number in series interactively or via command line argument<br \/>\n\/\/   fibonacci_series.cpp<br \/>\n\/\/   RJM Programming - December, 2022<br \/>\n<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n<br \/>\nchar aline[500];<br \/>\nint done=0;<br \/>\nint last=-1;<br \/>\nchar oneline[500];<br \/>\nchar lblanks[500];<br \/>\n\/\/int nums[]={0,1};<br \/>\nint lastf=0;<br \/>\nint lastlastf=0;<br \/>\n<br \/>\nint countFibonacci(int i) {  \/\/ Recursive function<br \/>\n    int fibonacci;<br \/>\n    if (i == 0) { return 0; } else if (i == 1) { if (done == 0) { done=1; sprintf((aline + strlen(aline)), \"1%s\", \" \"); } return 1; }<br \/>\n <br \/> <br \/>\n    fibonacci = countFibonacci(i-1) + countFibonacci(i-2);<br \/>\n    if (fibonacci &gt; last) {<br \/>\n      strcpy(aline, lblanks);<br \/>\n      strcat(aline, oneline);<br \/>\n      \/\/sprintf((aline + strlen(aline)), \"%d%s\", fibonacci, \", \");<br \/>\n      sprintf((aline + strlen(aline)), \"%d%s\", fibonacci, \" \");<br \/>\n      \/\/nums[1]=fibonacci;<br \/>\n    }<br \/>\n    last=fibonacci;<br \/>\n    return fibonacci;<br \/>\n}<br \/>\n<br \/>\nint main(int argc, char *args[]) {<br \/>\n        char delim[3]=\", \";<br \/>\n        char explanation[5000];<br \/>\n        int nsize = 0, fibonacci, i, j, k;<br \/>\n        char catend[20];<br \/>\n<br \/> <br \/>\n        \/\/ Check for argument 1 number in series<br \/>\n        if (argc &gt; 1) {<br \/>\n            for(i=0; i&lt;strlen(args[1]); i++) {<br \/>\n                if (args[1][i] == '-' || (args[1][i] &gt;= '0' && args[1][i] &lt;= '9')) {<br \/>\n                    nsize = nsize;<br \/>\n                } else if (args[0][i] != '-') {<br \/>\n                    nsize--;<br \/>\n                }<br \/>\n            }<br \/>\n            if (nsize == 0) sscanf(args[1], \"%d\", &nsize);<br \/>\n        }<br \/>\n        strcpy(explanation, \"\\n\\n\");<br \/>\n        strcpy(aline, \"0, \");<br \/>\n        oneline[0]=0;<br \/>\n        lblanks[0]=0;<br \/>\n        if (argc &lt;= 1) { \/\/nsize &lt;= 0) {<br \/>\n            \/\/printf(\"How many numbers are there in your fibonacci sequence (-ve for in a row): \");<br \/>\n            printf(\"How many numbers are there in your fibonacci sequence: \");<br \/>\n            scanf(\" %d\", &nsize);<br \/>\n        }<br \/>\n        \/\/if (nsize &gt; 0) {  strcpy(delim, \"\\n\\0\");   }<br \/>\n<br \/> <br \/>\n        for (i=-5; i&lt;=(int) abs(nsize * 3); i++) {<br \/>\n              sprintf((lblanks + strlen(lblanks)), \"%s\", \" \");<br \/>\n        }<br \/>\n        k=strlen(lblanks);<br \/>\n        strcpy(aline, lblanks);<br \/>\n        strcat(aline, \"0, \");<br \/>\n<br \/> <br \/>\n        for (i=0; i&lt;=(int) abs(nsize); i++) {<br \/>\n            fibonacci = countFibonacci(i);<br \/>\n            if (i == (int) abs(nsize)) {<br \/>\n              printf(\"%d\", fibonacci);<br \/>\n              sprintf((oneline + strlen(oneline)), \"%d%s\", fibonacci, \"\\0\");<br \/>\n              if (strstr(aline, \"1\")) {<br \/>\n                if (lastf != 0) {<br \/>\n                  sprintf(catend, \"%d%s%d%s%d%s\", lastlastf, \" + \", lastf, \" = \", fibonacci, \"\\n\");<br \/>\n                } else {<br \/>\n                  sprintf(catend, \"%d%s%d%s%d%s\", lastlastf, \" + \", 1, \" = \", fibonacci, \"\\n\");<br \/>\n                }<br \/>\n                strcat(explanation, strcat(strcat(aline, \"\\n \"), catend));<br \/>\n              }<br \/>\n              \/\/oneline[0]=0;<br \/>\n              aline[0]=0;<br \/>\n              k-=2;<br \/>\n              sprintf(lblanks, \"%s\", \"\\0\");<br \/>\n              for (j=0; j&lt;k; j++) {<br \/>\n                sprintf((lblanks + strlen(lblanks)), \"%s\", \" \");<br \/>\n              }<br \/>\n              sprintf(aline, \"%s%s\", lblanks, \"\\0\");<br \/>\n              strcat(aline, \"0, \");<br \/>\n              lastlastf=lastf;<br \/>\n              lastf=fibonacci;<br \/>\n           } else {<br \/>\n              printf(\"%d%s\", fibonacci, delim);<br \/>\n              sprintf((oneline + strlen(oneline)), \"%d%s%s\", fibonacci, delim, \"\\0\");<br \/>\n              if (strstr(aline, \"1\")) {<br \/>\n                if (lastf != 0) {<br \/>\n                  sprintf(catend, \"%d%s%d%s%d%s\", lastlastf, \" + \", lastf, \" = \", fibonacci, \"\\n\");<br \/>\n                } else {<br \/>\n                  sprintf(catend, \"%d%s%d%s%d%s\", lastlastf, \" + \", 1, \" = \", fibonacci, \"\\n\");<br \/>\n                }<br \/>\n                strcat(explanation, strcat(strcat(aline, \"\\n \"), catend));<br \/>\n              }<br \/>\n              \/\/oneline[0]=0;<br \/>\n              aline[0]=0;<br \/>\n              k-=2;<br \/>\n              sprintf(lblanks, \"%s\", \"\\0\");<br \/>\n              for (j=0; j&lt;k; j++) {<br \/>\n                sprintf((lblanks + strlen(lblanks)), \"%s\", \" \");<br \/>\n              }<br \/>\n              sprintf(aline, \"%s%s\", lblanks, \"\\0\");<br \/>\n              strcat(aline, \"0, \");<br \/>\n              lastlastf=lastf;<br \/>\n              lastf=fibonacci;<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/strcat(explanation, strcat(oneline, \" a new line\\n\"));<br \/>\n        printf(\"\\n%s\\n\", explanation);<br \/>\n}<br \/>\n<\/code><\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/new-c-recursion-find-revisit-tutorial\/'>New C Recursion Find Revisit Tutorial<\/a>.<\/p-->\n<hr>\n<p id='crfrt'>Previous relevant <a target=_blank title='C Recursion Find Revisit Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-find-revisit-tutorial\/'>C Recursion Find Revisit Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/better_find.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C Recursion Find Revisit Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/better_find.jpg\" title=\"C Recursion Find Revisit Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C Recursion Find Revisit Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='C Recursion Revisit Tutorial' href='#crrt'>C Recursion Revisit Tutorial<\/a> had us finding a macOS Xcode produced executable via the command line &#8220;find&#8221; command.  We find this excellent &#8220;find&#8221; command <i>trades off<\/i> the time it takes for the convenience to the user.  And this came into play when we noted, from yesterday&#8217;s &#8230;<\/p>\n<p><code><br \/>\nfind \/ -name 'Fibonacci' 2> \/dev\/null<br \/>\n<\/code><\/p>\n<p> &#8230; a mix of executable and non-executable files, causing a degree of confusion, and yet online published alternatives such as <i>find \/ -name &#8216;Fibonacci&#8217; -type f -executable 2> \/dev\/null<\/i> just didn&#8217;t work, and some solutions, such as an <i>xargs<\/i> one might need to wait for the whole list to be produced before producing any (hence our <i>trades off<\/i> assertion).  So, what else?  Well, <a target=_blank title='macOS find information' href='https:\/\/ss64.com\/osx\/find.html'>macOS &#8220;find&#8221;<\/a> has this useful &#8220;-ls&#8221; switch as per &#8230;<\/p>\n<blockquote cite=''><p>\n   -ls This primary always evaluates to true.  The following information<br \/>\n       for the current file is written to standard output: its inode<br \/>\n       number, size in 512-byte blocks, file permissions, number of hard<br \/>\n       links, owner, group, size in bytes, last modification time, and<br \/>\n       pathname.  If the file is a block or character special file, the<br \/>\n       major and minor numbers will be displayed instead of the size in<br \/>\n       bytes.  If the file is a symbolic link, the pathname of the<br \/>\n       linked-to file will be displayed preceded by &#8216;->&#8217;.  The format<br \/>\n       is identical to that produced by ls -dgils.\n<\/p><\/blockquote>\n<p> &#8230; that brings along information at each record that could help, and means we can <i>pipe<\/i> some extra (thanks to <a target=_blank title='Useful link, thanks' href='https:\/\/stackoverflow.com\/questions\/22727107\/how-to-find-the-last-field-using-cut'>this useful link<\/a> for ideas) &#8230;<\/p>\n<p><code><br \/>\nfind \/ -name 'Fibonacci' <b>-ls<\/b> 2> \/dev\/null <i>| grep 'rwx' | grep -v 'drwx' | rev | cut -d' ' -f 1 | rev<\/i><br \/>\n<\/code><\/p>\n<p> &#8230; to narrow the result set down to just executables for the longer &#8220;find&#8221; command line &#8220;parented&#8221; command set.  And the result is?  Yes, both files found were Xcode executables which worked, as you can see at <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/better_find.jpg\" title=\"Click picture\">today&#8217;s tutorial picture<\/a>.<\/p>\n<p>A word of warning here is that we do not know the behaviour, with methodology above, should filenames contain any blank characters.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-find-revisit-tutorial\/'>C Recursion Find Revisit Tutorial<\/a>.<\/p-->\n<hr>\n<p id='crrt'>Previous relevant <a target=_blank title='C Recursion Revisit Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-revisit-tutorial\/'>C Recursion Revisit Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/c_recursion_revisit.gif\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C Recursion Revisit Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/c_recursion_revisit.gif\" title=\"C Recursion Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C Recursion Revisit Tutorial<\/p><\/div>\n<p>Back in October, 2013 we presented <a title='C Recursion Primer Tutorial' href='#crpt'>C Recursion Primer Tutorial<\/a> as a C++ ( but really just straight C code) Xcode (<a target=_blank title='Integrated Development Environment information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Integrated_development_environment'>IDE<\/a>) project on Mac OS X.  That&#8217;s a long time ago, looking at it from late in 2021.  So what&#8217;s the go now with &#8230;<\/p>\n<ul>\n<li>macOS Big Sur v11.6 &#8230;<\/li>\n<li>Xcode Version 13.0 (13A233)<\/li>\n<\/ul>\n<p> &#8230; and while we are there, <a target=_blank title='main.cpp' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/main.cpp-GETME\">tweak the<\/a> <a target=_blank title='main.c' href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/main.c-GETME\">main.c<\/a>pp code because we&#8217;ve never found a &#8220;project revisit&#8221; yet, where we didn&#8217;t want to change something.<\/p>\n<p>You might be pleased to know that the <i>Xcode Version 13.0 (13A233)<\/i> way to setup this project &#8230;<\/p>\n<ol>\n<li>click Xcode (macOS desktop) icon<\/li>\n<li>File -&gt; New -&gt; Project&#8230;<\/li>\n<li>macOS (tab) &#8230; Application (section) &#8230; Command Line Tool &#8230; click Next<\/li>\n<li>Product Name &#8230; fill in a suitable project name (eg. Fibonacci)<\/li>\n<li>Language -&gt; C &#8230; click Next<\/li>\n<li>we just edited the project&#8217;s main.c for today&#8217;s &#8220;Fibonacci series revisit <i>with delimitation selection<\/i>&#8220;<\/li>\n<\/ol>\n<p> &#8230; does not require any <a target=_blank title='Code signing information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Code_signing'>&#8220;code signing&#8221;<\/a>.   Forgotten what C looks like?  A really simple C &#8220;main.c&#8221; can look like &#8230;<\/p>\n<p><code><br \/>\n\/\/   Fibonacci sequence<br \/>\n\/\/   Number in series interactively or via command line argument<br \/>\n<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n<br \/>\nint countFibonacci(int i) {  \/\/ Recursive function<br \/>\n    int fibonacci;<br \/>\n    if (i == 0) { return 0; } else if (i == 1) { return 1; }<br \/>\n<br \/> <br \/>\n    fibonacci = countFibonacci(i-1) + countFibonacci(i-2);<br \/>\n    return fibonacci;<br \/>\n}<br \/>\n<br \/>\nint main(int argc, char *args[]) {<br \/>\n        char delim[3]=\", \\0\";<br \/>\n        int nsize = 0, fibonacci, i;<br \/>\n<br \/> <br \/>\n        \/\/ Check for argument 1 number in series<br \/>\n        if (argc &gt; 1) {<br \/>\n            for(i=0; i&lt;strlen(args[1]); i++) {<br \/>\n                if (args[1][i] == '-' || (args[1][i] &gt;= '0' && args[1][i] &lt;= '9')) {<br \/>\n                    nsize = nsize;<br \/>\n                } else if (args[0][i] != '-') {<br \/>\n                    nsize--;<br \/>\n                }<br \/>\n            }<br \/>\n            if (nsize == 0) sscanf(args[1], \"%d\", &nsize);<br \/>\n        }<br \/>\n        if (argc &lt;= 1) { \/\/nsize &lt;= 0) {<br \/>\n            printf(\"How many numbers are there in your fibonacci sequence (-ve for in a row): \");<br \/>\n            scanf(\" %d\", &nsize);<br \/>\n        }<br \/>\n        if (nsize &gt; 0) {  strcpy(delim, \"\\n\\0\");   }<br \/>\n<br \/> <br \/>\n        for (i=0; i&lt;=(int) abs(nsize); i++) {<br \/>\n            fibonacci = countFibonacci(i);<br \/>\n            if (i == (int) abs(nsize)) { printf(\"%d\", fibonacci); } else {  printf(\"%d%s\", fibonacci, delim); }<br \/>\n        }<br \/>\n        printf(\"\\n\");<br \/>\n}<br \/>\n<\/code><\/p>\n<p><i><b>Did you know?<\/b><\/i><\/p>\n<p>Am sure we can hear a lot of you say &#8230;<\/p>\n<blockquote><p>Isn&#8217;t the &#8220;Command Line&#8221; bit of &#8220;Command Line Tool&#8221; a bit removed from how you Run the C program in Xcode?<\/p><\/blockquote>\n<p>We&#8217;d agree.  But every time you successfully Compile in Xcode a C (or C++) program, behind the scenes a [ProjectName] executable is created in a folder on your macOS computer.  We found where via &#8230;<\/p>\n<p><code><br \/>\nfind \/ -name 'Fibonacci' 2> \/dev\/null<br \/>\n<\/code><\/p>\n<p> &#8230; &#8220;Fibonacci&#8221; being our [ProjectName] today &#8230; and got back &#8230;<\/p>\n<p><code><br \/>\n\/System\/Volumes\/Data\/private\/var\/folders\/y2\/tw11n9vj5wv77xybybymdld00000gn\/T\/ba4bf3d76352a83c42e6ccf2829b5dd567ea7140\/Fibonacci<br \/>\n\/System\/Volumes\/Data\/Users\/user\/Library\/Developer\/Xcode\/DerivedData\/Fibonacci-ghevtgngocmwbcbpmalympfdifht\/Build\/Products\/Debug\/Fibonacci<br \/>\n\/System\/Volumes\/Data\/Applications\/MAMP\/htdocs\/Fibonacci<br \/>\n\/System\/Volumes\/Data\/Applications\/MAMP\/htdocs\/Fibonacci\/Fibonacci<br \/>\n\/private\/var\/folders\/y2\/tw11n9vj5wv77xybybymdld00000gn\/T\/ba4bf3d76352a83c42e6ccf2829b5dd567ea7140\/Fibonacci<br \/>\n\/Users\/user\/Library\/Developer\/Xcode\/DerivedData\/Fibonacci-ghevtgngocmwbcbpmalympfdifht\/Build\/Products\/Debug\/Fibonacci<br \/>\n\/Applications\/MAMP\/htdocs\/Fibonacci<br \/>\n\/Applications\/MAMP\/htdocs\/Fibonacci\/Fibonacci<br \/>\n<\/code><\/p>\n<p> &#8230; and ruling out the Xcode project last two places (which are distinct from where Xcode creates the executable) we deduced &#8230;<\/p>\n<p><code><br \/>\n\/System\/Volumes\/Data\/Users\/user\/Library\/Developer\/Xcode\/DerivedData\/Fibonacci-ghevtgngocmwbcbpmalympfdifht\/Build\/Products\/Debug\/Fibonacci -9<br \/>\n<\/code><\/p>\n<p> &#8230; would get us &#8230;<\/p>\n<p><code><br \/>\n0, 1, 1, 2, 3, 5, 8, 13, 21, 34<br \/>\n<\/code><\/p>\n<p> &#8230; as it should &#8230; on the &#8220;Command Line&#8221; (in Terminal application of macOS).<\/p>\n<p>More macOS command line &#8220;find&#8221; command refinement thoughts <a target=_blank title='C Recursion Revisit Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-find-revisit-tutorial'>tomorrow<\/a>!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-revisit-tutorial\/'>C Recursion Revisit Tutorial<\/a>.<\/p-->\n<hr>\n<p id='crpt'>Previous relevant <a target=_blank title='C Recursion Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-primer-tutorial\/'>C Recursion Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C Recursion Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/C_Recursion_Primer.jpg\" title=\"C Recursion Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C Recursion Primer Tutorial<\/p><\/div>\n<blockquote><p>Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur. The term is also used more generally to describe a process of repeating objects in a self-similar way.<\/p><\/blockquote>\n<p>\nRecursion is not just applicable to C.   Already we have shown the same scenario, which you can compare and contrast, here, in Java, with <a href='#jrpt' title='Java Recursion Primer Tutorial'>Java Recursion Primer Tutorial<\/a>, shown below.    It is a good technique to use in many programming applications unless its use becomes too esoteric.   It is usually true that a non-recursive technique can be used in place of the recursive technique.   As you might guess, you can reduce the size of your code using recursion in your code.  Recursive functions need an &#8220;anal&#8221; hard coded return, ahead of time, for the end-of-the-line value returned &#8230; as you see here for when i=1 or i=0 &#8230; if you don&#8217;t do this, it may be that your recursive function contributes to <a target=_blank title='Infinite Loop' href='https:\/\/www.youtube.com\/watch?v=1z7Mt2pwsuA'>infinite looping<\/a> &#8230; the stuff of nightmares.<\/p>\n<p>Today&#8217;s <a target=_blank title='C Recursion Primer Tutorial' href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/\">tutorial<\/a> in C(++) in Xcode shows you a way to find the path to your executable, the knowledge of which can then be applied to run the executable from a (Mac Terminal) Linux bash command line, as shown in the picture above and the last slide of the tutorial.<\/p>\n<p>Link to Recursion information &#8230;  <a target=_blank title='Recursion' href='http:\/\/en.wikipedia.org\/wiki\/Recursion'>via Wikipedia (as per information above)<\/a>.<\/p>\n<p>This <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/\">tutorial<\/a> shows the use of a recursive function used to show the Fibonacci Sequence of a designated sequence size, both interactively or via (Mac Terminal application Linux bash) command line arguments.<\/p>\n<blockquote><p>Liber Abaci also posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. The number sequence was known to Indian mathematicians as early as the 6th century,[10][11][12] but it was Fibonacci&#8217;s Liber Abaci that introduced it to the West.<\/p>\n<p>In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers, starting with 0 and 1. This sequence begins 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 &#8230; [13]<\/p>\n<p>The higher up in the sequence, the more closely the ratio of two consecutive Fibonacci numbers will approach the golden ratio (approximately 1 : 1.618 or 0.618 : 1).<\/p><\/blockquote>\n<p>Link to Fibonacci Sequence information &#8230;  <a target=_blank title='Fibonacci Sequence' href='http:\/\/en.wikipedia.org\/wiki\/Fibonacci'>via Wikipedia (as per information above)<\/a>.<\/p>\n<p>Link to &#8230; <a target=_blank title='Woah!' href='https:\/\/www.youtube.com\/watch?v=WZvVeq0dcKM&#038;list=PL9793D2E792FDF096'>Elementary my dear Watson!<\/a> &#8230; wow.<\/p>\n<p>Download programming code and rename to <a target=_blank title='main.cpp' href=\"http:\/\/www.rjmprogramming.com.au\/C\/Recursion\/main.cpp_GETME\">main.cpp<\/a> or main.c &#8230; depending on your environment.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d1208' onclick='var dv=document.getElementById(\"d1208\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Java\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d1208' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p id='jrpt'>Previous relevant (compare and contrast) <a target=_blank title='Java Recursion Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/'>Java Recursion Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Recursion\/Java_Recursive_Fibonacci.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Java Recursion Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Recursion\/Java_Recursive_Fibonacci.jpg\" title=\"Java Recursion Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Recursion Primer Tutorial<\/p><\/div>\n<blockquote><p>Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur. The term is also used more generally to describe a process of repeating objects in a self-similar way.<\/p><\/blockquote>\n<p>\nRecursion is not just applicable to Java.  It is a good technique to use in many programming applications unless its use becomes too esoteric.   It is usually true that a non-recursive technique can be used in place of the recursive technique.   As you might guess, you can reduce the size of your code using recursion in your code.  Recursive functions need an &#8220;anal&#8221; hard coded return, ahead of time, for the end-of-the-line value returned &#8230; as you see here for when i=1 or i=0 &#8230; if you don&#8217;t do this, it may be that your recursive function contributes to <a target=_blank title='Infinite Loop' href='https:\/\/www.youtube.com\/watch?v=1z7Mt2pwsuA'>infinite looping<\/a> &#8230; the stuff of nightmares.<\/p>\n<p>Link to Recursion information &#8230;  <a target=_blank title='Recursion' href='http:\/\/en.wikipedia.org\/wiki\/Recursion'>via Wikipedia (as per information above)<\/a>.<\/p>\n<p>This <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Recursion\/Java_Recursive_Fibonacci.jpg\">tutorial<\/a> shows the use of a recursive function used to show the Fibonacci Sequence of a designated sequence size.<\/p>\n<blockquote><p>Liber Abaci also posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. The number sequence was known to Indian mathematicians as early as the 6th century,[10][11][12] but it was Fibonacci&#8217;s Liber Abaci that introduced it to the West.<\/p>\n<p>In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers, starting with 0 and 1. This sequence begins 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 &#8230; [13]<\/p>\n<p>The higher up in the sequence, the more closely the ratio of two consecutive Fibonacci numbers will approach the golden ratio (approximately 1 : 1.618 or 0.618 : 1).<\/p><\/blockquote>\n<p>Link to Fibonacci Sequence information &#8230;  <a target=_blank title='Fibonacci Sequence' href='http:\/\/en.wikipedia.org\/wiki\/Fibonacci'>via Wikipedia (as per information above)<\/a>.<\/p>\n<p>Link to &#8230; <a target=_blank title='Woah!' href='https:\/\/www.youtube.com\/watch?v=WZvVeq0dcKM&#038;list=PL9793D2E792FDF096'>Elementary my dear Watson!<\/a> &#8230; wow.<\/p>\n<p>Download programming code and rename to <a target=_blank title='fibonacciRecursive.java' href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Recursion\/fibonacciRecursive.java_GETME\">fibonacciRecursive.java<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d1208' onclick='var dv=document.getElementById(\"d1208\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Java\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d1208' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4488' onclick='var dv=document.getElementById(\"d4488\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=C++\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4488' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d54364' onclick='var dv=document.getElementById(\"d54364\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/xcode\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d54364' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d54379' onclick='var dv=document.getElementById(\"d54379\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/find\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d54379' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d57753' onclick='var dv=document.getElementById(\"d57753\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/compiler\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d57753' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;re revisiting the Fibonacci Series code of C Recursion Find Revisit Tutorial and compiling it, plus some extended functionality, via the g++ c++ compiler on a macOS command line, as per &#8230; g++ fibonacci_series.cpp -o fibonacci_series.out &#8230; regarding the changed &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-recursion-fibonacci-series-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,29,37],"tags":[96,176,233,234,242,319,3882,3082,997,1034,4171,1319],"class_list":["post-57753","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-operating-system","category-tutorials","tag-application","tag-c","tag-command","tag-command-line","tag-compiler","tag-desktop","tag-fibonacci-series","tag-g","tag-programming","tag-recursion","tag-std","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57753"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=57753"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57753\/revisions"}],"predecessor-version":[{"id":57761,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57753\/revisions\/57761"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=57753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=57753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=57753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}