gdata.io.handleScriptLoaded({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$georss":"http://www.georss.org/georss","xmlns$thr":"http://purl.org/syndication/thread/1.0","xmlns$blogger":"http://schemas.google.com/blogger/2008","id":{"$t":"tag:blogger.com,1999:blog-8285804830535272268"},"updated":{"$t":"2023-07-30T02:11:08.392-07:00"},"category":[{"term":"C Programs"},{"term":"Pointers"},{"term":"string"},{"term":"Array"},{"term":"Learn C"},{"term":"Fundamental"},{"term":"Pattern"},{"term":"control sturctures"},{"term":"searching and sorting"},{"term":"recursion"},{"term":"List of C Programs"},{"term":"Structures"},{"term":"C Turbo Compiler"},{"term":"File Handling"},{"term":"Contents"},{"term":"Common Programming Error"},{"term":"functions"},{"term":"Dynamic memory allcation"}],"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/-/recursion?alt\u003djson-in-script\u0026max-results\u003d50"},{"rel":"self","type":"application/atom+xml","href":"https://www.comp-psyche.com/feeds/posts/default/-/recursion?alt\u003djson-in-script\u0026max-results\u003d50"},{"rel":"alternate","type":"text/html","href":"http://www.comp-psyche.com/search/label/recursion"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Mantu Kumar"},"uri":{"$t":"https://draft.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"generator":{"version":"7.00","uri":"https://draft.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":"recursion"},{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"}],"title":{"type":"text","$t":"C PROGRAMS : RECURSION"},"content":{"type":"html","$t":"\u003cdiv dir\u003d\"ltr\" style\u003d\"text-align: left;\" trbidi\u003d\"on\"\u003e\n\u003ctitle\u003eC PROGRAMS : RECURSION\u003c/title\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p6\" name\u003d\"p6\"\u003e6. Program to find whether a number is Palindrome or not using recursion\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e/*\n\nPalindrome Number : If Reverse of a number \u003d Number, the number is called Palindrome No.\n\nLOGIC : Reverse of a number is found by r\u003d(r*10)+d\nHere r\u003dreverser and d\u003ddigit extracted from the number.\n\n */\n\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n#include\u0026lt;stdio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\n// Declaring global variable r\u003dreverse, d\u003ddigit\nint r\u003d0, d\u003d0;\n\n// Defining function with parameter n \u003d number\nint rev(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u003d\u003d0)\nreturn r;\n\n// Continue calling function rev or function invoke itself\nelse\n{\n // Extracting digit\n d\u003dn%10;\n \n // Finding reverse\n r\u003d(r*10+d);\n \n // function invoke itself\n rev(n/10);\n}\n}\n\nint main()\n{\n// Declaring variable n \u003d 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\u003drev(n);\n\n// Checking and Displaying if a Number is palindrome or Not\nif(r\u003d\u003dn)\nprintf(\"%d is a Palindrome Number \",n);\n\nelse\nprintf(\"%d is not a Palindrome Number \",n);\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nreturn 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p7\" name\u003d\"p7\"\u003e7. Program to find whether a number is Armstrong or not using recursion\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e/*\n\n\u003cspan style\u003d\"color: blue;\"\u003eArmstrong Number : If sum of digits cube \u003d Number then it is called an Armstrong Number\n\nLOGIC : Sum of digits cube of a number is found by s\u003ds+d*d*d\nHere s\u003dsum and d\u003ddigit extracted from the number.\n\n */\n\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n#include\u0026lt;stdio.h\u0026gt;\n\n// Declaring global variable r\u003dreverse, d\u003ddigit\nint s\u003d0, d\u003d0;\n\n// Defining function with parameter n \u003d number\nint sum(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u003d\u003d0)\nreturn s;\n\n// Continue calling function sum or function invoke itself\nelse\n{\n // Extracting digit\n d\u003dn%10;\n \n // Finding reverse\n s\u003ds+d*d*d;\n \n // function invoke itself\n sum(n/10);\n}\n}\n\nint main()\n{\n// Declaring variable n \u003d 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\u003dsum(n);\n\n// Checking and Displaying if a Number is Armstron or Not\nif(s\u003d\u003dn)\nprintf(\"%d is an Armstrong Number \",n);\n\nelse\nprintf(\"%d is not an Armstrong Number \",n);\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nreturn 0;\n}\u003c/span\u003e\n\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p8\" name\u003d\"p8\"\u003e8. Program to print the fibonacci series upto nth terms using recursion\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e\u003cspan style\u003d\"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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\n// Defining function with parameter n \u003d number\nint fibo(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u003d\u003d1)\nreturn 0;\n\nelse if(n\u003d\u003d2)\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 \u003d number\nint n;\n\n/* Declaring variable \"i\" to iterate loop and \n\"term\"\u003dholds 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\u003d1;i\u0026lt;\u003dn;i++)\n{\n term\u003dfibo(i);\n printf(\"%d \",term);\n}\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nreturn 0;\n}\u003c/span\u003e\n\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p9\" name\u003d\"p9\"\u003e9. Program to print first \"n\" natural numbers in reverse order\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n#include\u0026lt;stdio.h\u0026gt;\n\n// Defining function with parameter n \u003d number\nvoid natural(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u0026lt;\u003d1)\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 \u003d 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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nreturn 0;\n}\u003c/span\u003e\n\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p10\" name\u003d\"p10\"\u003e10. Program to print pattern :\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e\u003cspan style\u003d\"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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nint recursion(i,j)\n{\nif(i\u0026gt;5)\nreturn 0;\nelse if(j\u0026lt;\u003di)\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\u003d\"color: blue;\"\u003e getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p11\" name\u003d\"p11\"\u003e11. Program to print pattern :\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\n\u003cpre\u003e\u003cspan style\u003d\"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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nint recursion(i,j,n)\n{\nif(i\u0026gt;n)\nreturn 0;\nelse if(j\u0026lt;\u003di)\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\u003d\"color: blue;\"\u003e getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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://draft.blogger.com/feeds/8285804830535272268/posts/default/3633621045680754238"},{"rel":"self","type":"application/atom+xml","href":"https://www.comp-psyche.com/feeds/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":"https://draft.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"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":"recursion"},{"scheme":"http://www.blogger.com/atom/ns#","term":"C Programs"}],"title":{"type":"text","$t":"C PROGRAMS : RECURSION"},"content":{"type":"html","$t":"\u003cdiv dir\u003d\"ltr\" style\u003d\"text-align: left;\" trbidi\u003d\"on\"\u003e\u003ctitle\u003eC PROGRAMS : RECURSION\u003c/title\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p1\" name\u003d\"p1\"\u003e1. Program to find the factorial of a Number using recursion\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\nint fact(int); // Function prototype\n\nint main()\n{\n// Declaring variable n\u003dnumber\nint n;\n\n// Decalring variable f \u003d 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\u003dfact(n);\n\n// Printing Factorial\nprintf(\"Factorial of %d \u003d %d \",n,f);\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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\u003d\u003d1)\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\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p2\" name\u003d\"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\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n#include\u0026lt;stdio.h\u0026gt;\n\n// Defining function with parameter n \u003d number\nint add(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u003d\u003d0)\nreturn 0;\n\n// Continue calling function add\nelse\nreturn n+add(n-1);\n}\nint main()\n{\n// Declaring variable n \u003d 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 \u003d %d\",add(n));\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\nreturn 0;\n}\u003c/span\u003e\n\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p3\" name\u003d\"p3\"\u003e3. Program to calculate the power using recursion. Example a^b ( Here ^ \u003d Power sign )\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e#include\u0026lt;stdio.h\u0026gt;\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\n// Defining function with parameter a\u003dNumber and b\u003dpower \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\u003d\u003d0)\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\u003d Number and b\u003dPower\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 \u003d %d \",a, b, power(a,b));\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p4\" name\u003d\"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\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"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\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\n// Defining function with parameter a \u003d First Number and b\u003dSecond 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\u003d\u003d0)\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\u003dFirst Number and b\u003dSecond 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 \u003d %d\",a,b,gcd(a,b));\n \n getch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n return 0;\n}\u003c/span\u003e\n\u003c/pre\u003e\u003c/div\u003e\u003cbr /\u003e\n\u003ca href\u003d\"http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p5\" name\u003d\"p5\"\u003e5. Program to Reverse a Number using recursion\u003c/a\u003e\u003cbr /\u003e\n\u003cdiv class\u003d\"mokcode\"\u003e\u003cpre\u003e\u003cspan style\u003d\"color: blue;\"\u003e/*\nLOGIC : Reverse of a number is found by r\u003d(r*10)+d\nHere r\u003dreverser and d\u003ddigit extracted from the number.\n\n */\n\n#include\u0026lt;conio.h\u0026gt; \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n#include\u0026lt;stdio.h\u0026gt;\n\n// Declaring global variable r\u003dreverse, d\u003ddigit\nint r\u003d0, d\u003d0;\n\n// Defining function with parameter n \u003d number\nint rev(int n)\n{\n/* Base condition : Any condition where a recursive function \nor method does not invoke itself. */\nif(n\u003d\u003d0)\nreturn r;\n\n// Continue calling function rev or function invoke itself\nelse\n{\n // Extracting digit\n d\u003dn%10;\n \n // Finding reverse\n r\u003d(r*10+d);\n \n // function invoke itself\n rev(n/10);\n}\n}\n\nint main()\n{\n// Declaring variable n \u003d 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 \u003d %d\",rev(n));\n\ngetch(); \u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e// Linux user - Remove this\u003c/span\u003e\u003cspan style\u003d\"color: blue;\"\u003e\n\u003c/span\u003e\u003cspan style\u003d\"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://draft.blogger.com/feeds/8285804830535272268/posts/default/8300709507896900255"},{"rel":"self","type":"application/atom+xml","href":"https://www.comp-psyche.com/feeds/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":"https://draft.blogger.com/profile/02897308282659594376"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"35","height":"35","src":"//www.blogger.com/img/blogger_logo_round_35.png"}}],"thr$total":{"$t":"0"}}]}});