 # Functions

## Types of Recursion With Examples

In this article, we will look into the different types of Recursion generally seen in programming to solve various problems. We will look at description of each type with example through code for better understanding. First of all, let’s have a quick recap of Recursion. In general, Recursion is an approach to solve problems where …

## C/C++ Program to Find GCD of Two Numbers Using Recursion

In this program we will use recursion and Euclid’s algorithm to find greatest common divisor of two numbers. The definition of Euclid’s algorithm is as follows: Also Read: C program to find factorial of any number using recursion Also Read: How to Convert a Recursive Function or Algorithm to Non-Recursive? C Program C++ Program

## C/C++ Program for Fibonacci Series Using Recursion

Series 0, 1, 1, 2, 3, 5, 8, 13, 21 . . . . . . . is a Fibonacci series. In Fibonacci series, each term is the sum of the two preceding terms.   The C and C++ program for Fibonacci series using recursion is given below.   C Program C++ Program   Output:

## C++ Templates: Program to Swap Two Numbers Using Function Template

What are Templates in C++? Templates help in defining generic classes and functions and hence allow generic programming. Generic programming is an approach where generic data types are used as parameters and the same piece of code work for various data types. Function templates are used to create family of functions with different argument types. …

## C++ Program to Compute High Precision Division for Integers

As we know, the arithmetic operations in programming languages are limited by precision accuracy. That means you will not get an exact answer but a rounded-close answer. For example, if you have 10 divided by 3 then you will get answer like 3.33333339555496.   The following program will describe a quick and efficient method to …

## What is Recursive Permutation in C++? [Algorithm and Source Code]

This article will describe a quick and easy algorithm that gives the full permutation for a natural number. The algorithm will be implemented by C++. A full permutation is list of all variation for given items (usually numbers). For example, the full permutation of 3 elements are: 1 2 3 1 3 2 2 1 …

## C program to find factorial of any number using recursion

#include<stdio.h> #include<conio.h> void main() { int fac,n; int factorial(int); clrscr(); printf(“Enter any number:”); scanf(“%d”,&n); fac=factorial(n); printf(“Factorial=%d”,fac); getch(); } int factorial(int x) { int f; if(x==1||x==0) return 1; else f=x*factorial(x-1); return f; }

## C++ program to swap values of two variables using pass by reference method

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b; void swap(int &,int &); cout<<“Enter two values:”; cin>>a>>b; cout<<“nBefor swapping:na=”<<a<<“tb=”<<b; swap(a,b); cout<<“nnAfter swapping:na=”<<a<<“tb=”<<b; getch(); } void swap(int & x,int & y) { int temp; temp=x; x=y; y=temp; }