| 1 | import java.util.*; |
| 2 | class FactorialN |
| 3 | { |
| 4 | public static int f; //Global variable |
| 5 | static void fct(int n) //Tail recursive version |
| 6 | { |
| 7 | if (n <= 1) |
| 8 | return; |
| 9 | f *= n; |
| 10 | fct(n-1); //All Set and done |
| 11 | } |
| 12 | /* |
| 13 | static int fct(int n) //Head recursive version |
| 14 | { |
| 15 | if (n <= 1) |
| 16 | return 1; |
| 17 | return (n * fct(n-1)); |
| 18 | // this n, makes the function here head recursive, as the function |
| 19 | // will have to return to its parent to do the multiplication, |
| 20 | // hence tail elimination cant be used |
| 21 | } |
| 22 | */ |
| 23 | public static void main(String args[]) |
| 24 | { |
| 25 | Scanner I = new Scanner(System.in); |
| 26 | System.out.println("Enter A Number"); |
| 27 | int n = I.nextInt(); |
| 28 | f = 1; |
| 29 | fct(n); |
| 30 | System.out.println("Your factorial is: " + f); |
| 31 | I.close(); |
| 32 | } |
| 33 | } |
nothing calls this directly
no outgoing calls
no test coverage detected