Function factorial (iterative) - Practice Exercises Java Lesson 5: Functions Exercise 5.23: Function factorial (iterative) Objetive: Create an iterative (non-recursive) function to calculate the factorial of the number specified as parameter: Console.Write ( Factorial (6) ); would display 720 Source Code: JAVA C# public class Main { public static float Factorial(int n) { int result = 1; for (int i = 1; i <= n; i++) { result *= i; } return result; } public static void main(String[] args) { System.out.print(Factorial(6)); } } Copy Exercise to ClipBoard Copy Code to ClipBoard Exercisey 5.23
More exercises for Lesson 5 Previous Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Next >>