Saturday, July 30, 2016

Factorial Using Pointers in C++

A simple program that I wrote for my programming class before in college factorial program using pointers in C++. What does the program will do is to ask the user to give a number and then our program will compute its factorial equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program 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