Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorial Of Number #32

Open
Krush2311 opened this issue Jan 5, 2024 · 2 comments
Open

Factorial Of Number #32

Krush2311 opened this issue Jan 5, 2024 · 2 comments
Labels
easy good first issue Good for newcomers question Further information is requested

Comments

@Krush2311
Copy link
Contributor

Krush2311 commented Jan 5, 2024

Write an algorithm to find factorial of a number entered by user in Java

@Krush2311 Krush2311 added good first issue Good for newcomers question Further information is requested easy labels Jan 5, 2024
@rautnandini31
Copy link

#include<stdio.h>

@hrugved005
Copy link

Here's the iterative approach to finding factorial of a number in java:-

public class FactorialIterative {
    public static long factorialIterative(int n) {
        long result = 1;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }

    public static void main(String[] args) {
        int number = 5;
        long result = factorialIterative(number);
        System.out.println("The factorial of " + number + " is: " + result);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants