# C program to Demonstrate the Recursive function.

Write a C program to demonstrate the recursive function.
Recursion  is the programming technique that a process invoking itself again and again. In this program, We reverse the given number and checks it is a palindrome or not. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>#include<conio.h>int main(){ clrscr(); int num,num1,rev; printf("nEnter a number :n"); scanf("%d",&num); num1=num; //call recursive function rev=reverse(num); printf("nAfter reverse the number is :n%d",rev); if(num1==rev){  printf("nnNumber  %d is Palindromen",num1); }else {  printf("nnNumber  %d is NOT a Palindromen",num1); } return 0;}int sum=0,r;reverse(int num){ if(num){  r=num%10;  sum=sum*10+r;  reverse(num/10); } else  return sum; return sum;}`
`Read more Similar C ProgramsLearn C ProgrammingRecursionNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# K & R C Programs Exercise 4-13.

K and R C, Solution to Exercise 4-13:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
Write a C Program to reverse the string using the recursive methods.
In this program reverse determines the length of the string and then calls the reverser, which reverses the string s in place. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>/* reverse: reverse the string s in place */void reverse(char s[]){ void reverser(char s[], int i, int len); reverser(s,0,strlen(s));}/* reverser: reverse string s in place recursive */void reverser(char s[], int i, int len){ int c, j; j = len - (i + 1); if(i < j) {  c = s[i];  s[i] = s[j];  s[j] = c;  reverser(s, ++i, len); }}`
`Read more Similar C ProgramsC BasicC StringsK and R C Programs Exercise`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# K & R C Programs Exercise 4-12.

K and R C, Solution to Exercise 4-12:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
Write a C program to convert an integer into a string by calling a recursive routine.Recursive routine is the programming technique that a routine invoking itself again and again. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<math.h>void itoa(int n, char s[]);int main(void) { char buffer[20]; //for testing! printf("INT_MIN: %dn", INT_MIN); itoa(INT_MIN, buffer); printf("Buffer : %sn", buffer); return 0;}/* itoa: convert n to characters in s; recursive */void itoa(int n, char s[]){ static int i; if(n / 10)  itoa(n /10, s); else{  i = 0;  if(n < 0)   s[i++] = '-'; } s[i++] = abs(n) %10 + '0'; s[i] = '';}`
`Read more Similar C ProgramsC BasicC StringsK and R C Programs Exercise`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# C Program to find GCD and LCM using Recursion

C Program to find the GCD and LCM. In this program we used the Recursion method. Recursion is the programming technique that a process invoking itself again and again. Here find_gcd() and find_(lcm) are the recursive methods. for example LCM and GCD of 8,12 is 24 and 4 Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!*  *                      Happy Coding***********************************************************//* * http://www.c-program-example.com/2011/10/c-program-to-find-gcd-and-lcm-using.html*/ /* Find this on GitHub: *  https://github.com/snadahalli/cprograms/blob/master/gcd_lcm_rec.c*/#include "stdio.h"int find_gcd(int,int);int find_lcm(int,int);int main(){ int num1,num2,gcd,lcm; printf("nEnter two numbers:n "); scanf("%d %d",&num1,&num2); gcd=find_gcd(num1,num2);  printf("nnGCD of %d and %d is: %dnn",num1,num2,gcd);  if(num1>num2)  lcm = find_lcm(num1,num2); else  lcm = find_lcm(num2,num1);  printf("nnLCM of %d and %d is: %dnn",num1,num2,lcm); return 0;} int find_gcd(int n1,int n2){ while(n1!=n2){  if(n1>n2)   return find_gcd(n1-n2,n2);  else   return find_gcd(n1,n2-n1); } return n1;}int find_lcm(int n1,int n2){  static int temp = 1;  if(temp % n2 == 0 && temp % n1 == 0)  return temp; temp++; find_lcm(n1,n2);  return temp;}`
`Read more Similar C ProgramsLearn C ProgrammingRecursionNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

(c) www.c-program-example.com

# C program to print Fibonacci numbers using Recursion

C Program to print Fibonacci numbers. In this program we used the Recursion method. Recursion is the programming technique that a process invoking itself again and again. Fibonacci numbers are sequence of numbers starts from 0 and 1 , continue by adding previous number. 0,1,1,2,3,5,8,13,…….. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h> #include<conio.h> int fib(int); int f=1,fib1=0,fib2=0,i=0,j; void main() {  int num;  clrscr();  printf(" How many Fibonacci numbers do you want?n");  scanf("%d",&num);  printf("nFibonacci Numbers are:n"); f=0;  printf("n%dn",f);  f=1;  printf("n%dn",f);  for(j=0;j<num-2;j++)  {   f=fib(num);   printf("n%dn",f);  }  getch(); } int fib(int n) {  while(i<n)  {   if(i<=n)   {    i++;    fib1=fib2;    fib2=f;    f=fib2+fib1;    fib(1);    return f;   }  } } `
`Read more Similar C ProgramsLearn C ProgrammingRecursionNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

(c) www.c-program-example.com

# C Program to calculate factorial using Recursive function

C Program to find the factorial of a number. In this program we used the Recursion method. Recursion is the programming technique that a process invoking itself again and again. The standard recursive function for factorial is factorial=n*fact(n-1). factorial of number denoted by ‘!’, means product of all non negative integers from 1 to number. example: 5!=5*4*3*2*1=120. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>int factorial(int);void main(){ int num; printf("Enter the number to calculate Factorial :"); scanf("%d",&num); printf("nFactorial : %d", factorial (num));}int factorial (int i){ int f; if(i==1)  return 1; else  f = i* factorial (i-1); return f;}`
`Read more Similar C ProgramsLearn C ProgrammingRecursionNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

(c) www.c-program-example.com

# C program to implement Towers of Hanoi and Binary Search

C Recursion:
C Program to implement Towers of Hanoi and Binary Search using the Recursion method. Recursive functions solves the complexity of the problem by calling the function again and again itself. Using recursive methods we can save execution time and memory. In this program we have two recursive functions for Binary search and the Tower of Hanoi problem. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                                  Happy Coding***********************************************************/#include<stdio.h>main() { int n, a[50], key, opn, i, pos; do {  clrscr();  printf(    " nn Press 1 -> Binary Search , 2-> Towers of Hanoi 3-> Quitn");  scanf("%d", &opn);  switch (opn) {  case 1:   printf(" How Many Elements?");   scanf("%d", &n);   printf(" Read all the elements is ASC order n");   for (i = 1; i <= n; i++)    scanf("%d", &a[i]);   printf(" Read the Key Elementn");   scanf("%d", &key);   pos = BS(a, key, 1, n);   if (pos)    printf(" Success: %d found at %d n", key, pos);   else    printf(" Falure: %d Not found in the list ! n", key);   break;  case 2:   printf("nn How Many Disks ?");   scanf("%d", &n);   printf("nn Result of Towers of Hanoi for %d Disks n", n);   tower(n, 'A', 'B', 'C');   printf("nn Note: A-> Source, B-> Intermediate, C-> Destinationn");   break;  case 3:   printf(" Terminating n");   break;  default:   printf(" Invalid Option !! Try Again !! n");  }  printf(" Press a Key. . . ");  getch(); } while (opn != 3);}int BS(int a[], int key, int low, int high) { int mid; if (low > high)  return 0; /* failure */ else {  mid = (low + high) / 2;  if (a[mid] == key)   return mid; /* Success */  if (key < a[mid])   return (BS(a, key, low, mid - 1));  return (BS(a, key, mid + 1, high)); }}tower(int n, char src, char intr, char dst) { if (n > 0) {  tower(n - 1, src, dst, intr);  printf("Move disk %d from %c to %c n", n, src, dst);  tower(n - 1, intr, src, dst); }}`
`Read more Similar C ProgramsData Structures C Recursion`

You can easily select the code by double clicking on the code area above.