{"id":4593,"date":"2023-01-02T10:09:32","date_gmt":"2023-01-02T10:09:32","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=4593"},"modified":"2023-01-02T10:09:34","modified_gmt":"2023-01-02T10:09:34","slug":"c-program-to-find-nth-fibonacci-number","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/c-program-to-find-nth-fibonacci-number\/","title":{"rendered":"C program to find nth fibonacci number"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">C program to find nth fibonacci number<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this program, we are going to find out the nth Fibonacci number. So let&#8217;s start!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For example-<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Input<\/strong>&#8211;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, we take input from the user to suppose we take 12<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Logic-<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">|Basically to find out the Fibonacci number, there is one formula to calculate these and the formula is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fn = Fn-1 + Fn-2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output &#8211;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">According to our input, we take the output as<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter a number: 12<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The 12th Fibonacci number is 144<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/ C program to find nth fibonacci number.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">#include &lt;stdio.h&gt;<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">long fibonacci(int num)<br>{<br>if (num &lt;= 1)<br>return num;<br>return fibonacci(num &#8211; 1) + fibonacci(num &#8211; 2);<br>}<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">int main()<br>{<br>int num;<br>printf(&#8220;Enter a number: &#8220;);<br>scanf(&#8220;%d&#8221;, &amp;num);<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">printf(&#8220;nThe %dth fibonacci number is %ld&#8221;, num, fibonacci(num));<br>return 0;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter a number: 12<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The 12th Fibonacci number is 144<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Steps to find out the nth Fibonacci number:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1:<\/strong> Create a user-defined function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong> Apply the formula to find out the nth Fibonacci number<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fn = Fn-1 + Fn-2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3:<\/strong> Create the main function<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4:<\/strong> Get a number from the user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5:<\/strong> return the value to the function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 6:<\/strong> Execute the program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So In this way, we simply calculate the nth Fibonacci number using the function. I hope this concept is clear to you. You can also explore these concepts by using another number.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep learning, and keep exploring!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C program to find nth fibonacci number In this program, we are going to find out the nth Fibonacci number. So let&#8217;s start! For example- Input&#8211; First, we take input from the user to suppose we take 12 Logic- |Basically to find out the Fibonacci number, there is one formula to calculate these and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[29,104],"class_list":["post-4593","post","type-post","status-publish","format-standard","category-c-program","tag-c-program","tag-c-program-to-find-nth-fibonacci-number"],"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=4593"}],"version-history":[{"count":1,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4593\/revisions"}],"predecessor-version":[{"id":4594,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4593\/revisions\/4594"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=4593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=4593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=4593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}