C++ Programming: Build an Factorial(a) function. Write a function to calculate t
ID: 3673383 • Letter: C
Question
C++ Programming:Build an Factorial(a) function. Write a function to calculate the factorial value of any integer as an argument. Call this function from main() and print the results in main( ). The Factorial() function should go after the main function, not before.
Use a function signature/declaration before main(). C++ Programming:
Build an Factorial(a) function. Write a function to calculate the factorial value of any integer as an argument. Call this function from main() and print the results in main( ). The Factorial() function should go after the main function, not before.
Use a function signature/declaration before main().
Build an Factorial(a) function. Write a function to calculate the factorial value of any integer as an argument. Call this function from main() and print the results in main( ). The Factorial() function should go after the main function, not before.
Use a function signature/declaration before main(). Build an Factorial(a) function. Write a function to calculate the factorial value of any integer as an argument. Call this function from main() and print the results in main( ). The Factorial() function should go after the main function, not before.
Use a function signature/declaration before main().
Explanation / Answer
#include<iostream>
#include<conio.h>
using namespace std;
//Function
long factorial(int);
int main()
{
// Variable Declaration
int counter, n;
// Get Input Value
cout<<"Enter the Number :";
cin>>n;
// Factorial Function Call
cout<<n<<" Factorial Value Is "<<factorial(n);
getch();
return 0;
}
// Factorial Function
long factorial(int n)
{
int counter;
long fact = 1;
for (int counter = 1; counter <= n; counter++)
{
fact = fact * counter;
}
return fact;
}