Factorial of a number without using multiplication | Java program for the above approach ; Function to calculate factorial of the number without using multiplication operator ; variable to store the final factorial ; Outer loop ; Inner loop ; Driver code ; Input ; Function calling
import java . io . * ; class GFG { public static int factorialWithoutMul ( int N ) { int ans = N ; for ( int i = N - 1 ; i > 0 ; i -- ) { int sum = 0 ; for ( int j = 0 ; j < i ; j ++ ) sum += ans ; ans = sum ; } return ans ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( factorialWithoutMul ( N ) ) ; } }