Saturday, May 2, 2015

Factorial of Numbers Using Recursion Pointers in C++

Recursion is one of the most common method that is being used in programming to solve a problem for example factorial of numbers in C++. In this article I will show you how to solve factorial of number using recursion with pointers in C++. The code is very straight forward it uses functions to accomplish the result. I hope you will find my work useful in your study of C++ programming.

If you like my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines who wish to contact me can call and text me in this number 09173084360.

Thank you very much and God Bless.



Sample Output


Program Listing


#include <iostream>

using namespace std;

int factorial (int num)
{
 if (num==1)
  return 1;
 return factorial(num-1)*num;
}

main() {
    int value=0;
    int *p;
    cout << "\t Recursion using Pointers";
    cout << "\n\n";
    cout << "Enter a Number :=> ";
    cin >> value;
    p = &value;
    cout << "\n";
    cout <<"The factorial value of " << value
        << " is " << factorial(value) << ".";
    cout << "\n\n";
    system("pause");
}



No comments:

Post a Comment