// API callback
relpostimgcuplik({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268"},"updated":{"$t":"2023-07-30T02:11:08.392-07:00"},"category":[{"term":"C Programs"},{"term":"Learn C"},{"term":"Common Programming Error"},{"term":"searching and sorting"},{"term":"control sturctures"},{"term":"Fundamental"},{"term":"List of C Programs"},{"term":"string"},{"term":"Array"},{"term":"Pattern"},{"term":"Contents"},{"term":"Pointers"},{"term":"functions"},{"term":"Dynamic memory allcation"},{"term":"recursion"},{"term":"C Turbo Compiler"},{"term":"File Handling"},{"term":"Structures"}],"title":{"type":"text","$t":"C Programming Tutorial"},"subtitle":{"type":"html","$t":"It is a blog about c programming. Here we provide c programs and tutorials to enhance your skills."},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/-\/recursion?alt=json-in-script\u0026max-results=50"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/search\/label\/recursion"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"2"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"50"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268.post-3633621045680754238"},"published":{"$t":"2014-01-29T05:03:00.000-08:00"},"updated":{"$t":"2015-05-24T06:19:28.970-07:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"},{"scheme":"http://www.blogger.com/atom/ns#","term":"recursion"}],"title":{"type":"text","$t":"C PROGRAMS : RECURSION"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\n\u003Ctitle\u003EC PROGRAMS : RECURSION\u003C\/title\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p6\" name=\"p6\"\u003E6. Program to find whether a number is Palindrome or not using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/*\n\nPalindrome Number : If Reverse of a number = Number, the number is called Palindrome No.\n\nLOGIC : Reverse of a number is found by r=(r*10)+d\nHere r=reverser and d=digit extracted from the number.\n\n *\/\n\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n#include\u0026lt;stdio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\/\/ Declaring global variable r=reverse, d=digit\nint r=0, d=0;\n\n\/\/ Defining function with parameter n = number\nint rev(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==0)\nreturn r;\n\n\/\/ Continue calling function rev or function invoke itself\nelse\n{\n \/\/ Extracting digit\n d=n%10;\n \n \/\/ Finding reverse\n r=(r*10+d);\n \n \/\/ function invoke itself\n rev(n\/10);\n}\n}\n\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/\/ Declaring variable \"r\" to hold the reverse number\nint r;\n\n\/\/ Inputting Number\nprintf(\"Enter the Number : \");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling function \"rev\" with actual parameter \"n\" passed to it\nr=rev(n);\n\n\/\/ Checking and Displaying if a Number is palindrome or Not\nif(r==n)\nprintf(\"%d is a Palindrome Number \",n);\n\nelse\nprintf(\"%d is not a Palindrome Number \",n);\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p7\" name=\"p7\"\u003E7. Program to find whether a number is Armstrong or not using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\/*\n\n\u003Cspan style=\"color: blue;\"\u003EArmstrong Number : If sum of digits cube = Number then it is called an Armstrong Number\n\nLOGIC : Sum of digits cube of a number is found by s=s+d*d*d\nHere s=sum and d=digit extracted from the number.\n\n *\/\n\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n#include\u0026lt;stdio.h\u0026gt;\n\n\/\/ Declaring global variable r=reverse, d=digit\nint s=0, d=0;\n\n\/\/ Defining function with parameter n = number\nint sum(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==0)\nreturn s;\n\n\/\/ Continue calling function sum or function invoke itself\nelse\n{\n \/\/ Extracting digit\n d=n%10;\n \n \/\/ Finding reverse\n s=s+d*d*d;\n \n \/\/ function invoke itself\n sum(n\/10);\n}\n}\n\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/\/ Declaring variable \"s\" to hold the sum of digits cube of number\nint s;\n\n\/\/ Inputting Number\nprintf(\"Enter the Number : \");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling function \"sum\" with actual parameter \"n\" passed to it\ns=sum(n);\n\n\/\/ Checking and Displaying if a Number is Armstron or Not\nif(s==n)\nprintf(\"%d is an Armstrong Number \",n);\n\nelse\nprintf(\"%d is not an Armstrong Number \",n);\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p8\" name=\"p8\"\u003E8. Program to print the fibonacci series upto nth terms using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/* \n\nFibonacci Series : 0 1 1 2 3 5 8 13 21 34 upto nth terms.\n\n*\/\n\n#include\u0026lt;conio.h\u0026gt;\n#include\u0026lt;stdio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\/\/ Defining function with parameter n = number\nint fibo(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==1)\nreturn 0;\n\nelse if(n==2)\nreturn 1;\n\n\/\/ Continue calling function fibo\nelse if(n\u0026gt;2)\nreturn fibo(n-1)+fibo(n-2);\n}\n\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/* Declaring variable \"i\" to iterate loop and \n\"term\"=holds the current number to help print the fibonacci series *\/\nint i, term;\n\n\/\/ Inputting Number\nprintf(\"Enter the value of n\\n\");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling function fibo with actual parameter \"n\" passed to it and displaying the value.\nfor(i=1;i\u0026lt;=n;i++)\n{\n term=fibo(i);\n printf(\"%d \",term);\n}\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p9\" name=\"p9\"\u003E9. Program to print first \"n\" natural numbers in reverse order\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n#include\u0026lt;stdio.h\u0026gt;\n\n\/\/ Defining function with parameter n = number\nvoid natural(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n\u0026lt;=1)\nprintf(\"%d \",n);\n\n\/\/ Continue calling function natural\nelse\n{\n printf(\"%d \",n);\n natural(n-1);\n}\n\n\n}\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/\/ Inputting Number\nprintf(\"Enter the value of n\\n\");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Displaying the value.\nprintf(\"First %d Natural Numbers in reverse order : \\n\",n);\n\n\/\/ Calling function natural with actual parameter \"n\" passed to it \nnatural(n);\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p10\" name=\"p10\"\u003E10. Program to print pattern :\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/*\n\n*\n* *\n* * * \n* * * *\n* * * * *\n\n *\/\n\n#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nint recursion(i,j)\n{\nif(i\u0026gt;5)\nreturn 0;\nelse if(j\u0026lt;=i)\n{\n printf(\"* \");\n recursion(i,j+1);\n}\nelse\n{\nprintf(\"\\n\");\nrecursion(i+1,1); \n}\n}\nint main()\n{ \n recursion(1,1);\n\u0026nbsp;\u003C\/span\u003E\u003C\/pre\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#p11\" name=\"p11\"\u003E11. Program to print pattern :\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/*\n\n*\n* *\n* * * \n* * * *\n* * * * * till n terms\n\n *\/\n\n\n#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nint recursion(i,j,n)\n{\nif(i\u0026gt;n)\nreturn 0;\nelse if(j\u0026lt;=i)\n{\n printf(\"* \");\n recursion(i,j+1,n);\n}\nelse\n{\nprintf(\"\\n\");\nrecursion(i+1,1,n); \n}\n}\nint main()\n{ int n;\n printf(\"Enter the value till which you want to print the patter:\");\n scanf(\"%d\",\u0026amp;n);\n recursion(1,1,n);\n\u0026nbsp;\u003C\/span\u003E\u003C\/pre\u003E\n\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/3633621045680754238\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/3633621045680754238"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/3633621045680754238"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion1.html","title":"C PROGRAMS : RECURSION"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268.post-8300709507896900255"},"published":{"$t":"2014-01-29T04:47:00.000-08:00"},"updated":{"$t":"2014-04-16T01:05:06.631-07:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"},{"scheme":"http://www.blogger.com/atom/ns#","term":"recursion"}],"title":{"type":"text","$t":"C PROGRAMS : RECURSION"},"content":{"type":"html","$t":"\u003Cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003E\u003Ctitle\u003EC PROGRAMS : RECURSION\u003C\/title\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#p1\" name=\"p1\"\u003E1. Program to find the factorial of a Number using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\nint fact(int); \/\/ Function prototype\n\nint main()\n{\n\/\/ Declaring variable n=number\nint n;\n\n\/\/ Decalring variable f = to hold the value of factorial\nint f;\n\n\/\/ Inputting Number\nprintf(\"Enter the Number : \");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling Factorial function\nf=fact(n);\n\n\/\/ Printing Factorial\nprintf(\"Factorial of %d = %d \",n,f);\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\n\nint fact(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==1)\nreturn 1;\n\n\/\/ Continue calling function fact\nelse\nreturn n*fact(n-1);\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003Cdiv\u003E\u003Cbr \/\u003E\n\u003C\/div\u003E\u003C\/div\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#p2\" name=\"p2\"\u003E2. Program to print sum of n natural numbers from 1 to n ( Number ) using recursion \u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n#include\u0026lt;stdio.h\u0026gt;\n\n\/\/ Defining function with parameter n = number\nint add(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==0)\nreturn 0;\n\n\/\/ Continue calling function add\nelse\nreturn n+add(n-1);\n}\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/\/ Inputting Number\nprintf(\"Enter the value of n\\n\");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling function add with actual parameter \"n\" passed to it and displaying the value.\nprintf(\"Sum of first n numbers = %d\",add(n));\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#p3\" name=\"p3\"\u003E3. Program to calculate the power using recursion. Example a^b ( Here ^ = Power sign )\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\/\/ Defining function with parameter a=Number and b=power \nint power(int a, int b)\n{\n \/* Base condition : Any condition where a recursive function \n or method does not invoke itself. *\/\n if(b==0)\n return 1;\n \n \/\/ Continue calling function power or function invoke itself\n else\n return a*power(a,b-1);\n}\n\nint main()\n{\n \/\/ Declaring variable a= Number and b=Power\n int a, b;\n \n \/\/ Inputting Number \n printf(\"Enter Number : \");\n scanf(\"%d\",\u0026amp;a);\n \n \/\/ Inputting Power\n printf(\"Enter Power : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Calling funciton power and displaying value returned by it.\n printf(\"%d ^ %d = %d \",a, b, power(a,b));\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\u003C\/pre\u003E\u003C\/div\u003E\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#p4\" name=\"p4\"\u003E4. Program to find the GCD ( Greatest Common Divisior ) or HCD ( Highes Common Factor ) using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/* \n\nLOGIC : \n\nThe gcd of \"a\" and \"b\" is the same as the gcd of \"a\" and \"a%b\"\n\n*\/\n\n#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\n\/\/ Defining function with parameter a = First Number and b=Second Number\nint gcd(int a, int b)\n{\n \/* Base condition : Any condition where a recursive function \n or method does not invoke itself. *\/\n if(b==0)\n return a;\n \n \/\/ Continue calling function gcd or function invoke itself\n else\n return gcd(b,a%b);\n}\n\nint main()\n{\n \/\/ Declaring variable a=First Number and b=Second Number\n int a,b;\n \n \/\/ Inputting First Number\n printf(\"Enter First Number : \");\n scanf(\"%d\",\u0026amp;a);\n \n \/\/ Inputting Second Number\n printf(\"Enter First Number : \");\n scanf(\"%d\",\u0026amp;b);\n \n \/\/ Calling funciton gcd and displaying value returned by it.\n printf(\"GCD of %d, %d = %d\",a,b,gcd(a,b));\n \n getch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n return 0;\n}\u003C\/span\u003E\n\u003C\/pre\u003E\u003C\/div\u003E\u003Cbr \/\u003E\n\u003Ca href=\"http:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#p5\" name=\"p5\"\u003E5. Program to Reverse a Number using recursion\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"mokcode\"\u003E\u003Cpre\u003E\u003Cspan style=\"color: blue;\"\u003E\/*\nLOGIC : Reverse of a number is found by r=(r*10)+d\nHere r=reverser and d=digit extracted from the number.\n\n *\/\n\n#include\u0026lt;conio.h\u0026gt; \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n#include\u0026lt;stdio.h\u0026gt;\n\n\/\/ Declaring global variable r=reverse, d=digit\nint r=0, d=0;\n\n\/\/ Defining function with parameter n = number\nint rev(int n)\n{\n\/* Base condition : Any condition where a recursive function \nor method does not invoke itself. *\/\nif(n==0)\nreturn r;\n\n\/\/ Continue calling function rev or function invoke itself\nelse\n{\n \/\/ Extracting digit\n d=n%10;\n \n \/\/ Finding reverse\n r=(r*10+d);\n \n \/\/ function invoke itself\n rev(n\/10);\n}\n}\n\nint main()\n{\n\/\/ Declaring variable n = number\nint n;\n\n\/\/ Inputting Number\nprintf(\"Enter the Number : \");\nscanf(\"%d\",\u0026amp;n);\n\n\/\/ Calling function \"rev\" with actual parameter \"n\" passed to it and displaying the value.\nprintf(\"Reverse of number = %d\",rev(n));\n\ngetch(); \u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\/\/ Linux user - Remove this\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\n\u003C\/span\u003E\u003Cspan style=\"color: blue;\"\u003E\nreturn 0;\n}\u003C\/span\u003E\n\n\u003C\/pre\u003E\u003C\/div\u003E\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.comp-psyche.com\/feeds\/8300709507896900255\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/8300709507896900255"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/8285804830535272268\/posts\/default\/8300709507896900255"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.comp-psyche.com\/2014\/01\/c-programs-recursion.html","title":"C PROGRAMS : RECURSION"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}}]}});