Skip to content

Instantly share code, notes, and snippets.

@RahulBRB
Created September 16, 2022 10:07
Show Gist options
  • Save RahulBRB/684847f94cd0b6ea65567ef0e133a51e to your computer and use it in GitHub Desktop.
Save RahulBRB/684847f94cd0b6ea65567ef0e133a51e to your computer and use it in GitHub Desktop.
Factorial using iterative approach
#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