Created
June 2, 2018 04:48
-
-
Save thmain/469886811d1d86a9214a6cc35c699783 to your computer and use it in GitHub Desktop.
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
public class FactorialIterative { | |
public static int factorial(int num){ | |
if(num==0) | |
return 1; | |
int result = 1; | |
for (int i = 2; i <=num ; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
public static void main(String[] args) { | |
int num = 7; | |
int fact = factorial(num); | |
System.out.println("Factorial of a number: " + num + " is(Iterative): " + fact); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment