mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Merge branch 'document/math' into document/temp
* document/math: replace printf & scanf with std::cout and std::cin documented factorial
This commit is contained in:
commit
76278a76c8
@ -1,14 +1,17 @@
|
|||||||
// C++ program to find factorial of given number
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief C++ program to find factorial of given number
|
||||||
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// function to find factorial of given number
|
/** function to find factorial of given number */
|
||||||
unsigned int factorial(unsigned int n) {
|
unsigned int factorial(unsigned int n) {
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 1;
|
return 1;
|
||||||
return n * factorial(n - 1);
|
return n * factorial(n - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver code
|
/** Main function */
|
||||||
int main() {
|
int main() {
|
||||||
int num = 5;
|
int num = 5;
|
||||||
std::cout << "Factorial of " << num << " is " << factorial(num)
|
std::cout << "Factorial of " << num << " is " << factorial(num)
|
||||||
|
@ -81,10 +81,10 @@ void power(int x, int n) {
|
|||||||
/** Main function */
|
/** Main function */
|
||||||
int main() {
|
int main() {
|
||||||
int exponent, base;
|
int exponent, base;
|
||||||
printf("Enter base ");
|
std::cout << "Enter base ";
|
||||||
scanf("%id \n", &base);
|
std::cin >> base;
|
||||||
printf("Enter exponent ");
|
std::cout << "Enter exponent ";
|
||||||
scanf("%id", &exponent);
|
std::cin >> exponent;
|
||||||
power(base, exponent);
|
power(base, exponent);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user