Factorial program in C++ with call-by-reference
Advertisement
Advertisement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<iostream> using namespace std; void Factorial(int, int *); int main() { int Mynum, fact=1; cout<<"Enter the Mynumber: "; cin>>Mynum; Factorial(Mynum, &fact); cout<<"\nFactorial = "<<fact; cout<<endl; return 0; } void Factorial(int n, int *f) { int i; for(i=n; i>=1; i--) *f = (*f)*i; } |
Output
Enter the Number: 4
Factorial = 24
Advertisement