Created
September 16, 2022 10:07
-
-
Save RahulBRB/684847f94cd0b6ea65567ef0e133a51e to your computer and use it in GitHub Desktop.
Factorial using iterative approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
int factorial(int num); | |
int main(){ | |
std::cout << factorial(5); | |
return 0; | |
} | |
int factorial(int num){ | |
int result = 1; | |
for(int i=1;i<=num;i++){ | |
result = result * i; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment