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

Added Factorial in SCALA #2099

Merged
merged 5 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion archive/s/scala/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Welcome to Sample Programs in Scala!
- [Game of Life in Scala](https://github.com/TheRenegadeCoder/sample-programs/issues/1035)
- [Quicksort in Scala](https://github.com/TheRenegadeCoder/sample-programs/issues/1034)
- [Reverse String in Scala](https://github.com/TheRenegadeCoder/sample-programs/issues/1032)

- [Factorial in Scala](https://github.com/TheRenegadeCoder/sample-programs-website/issues/332)
## Fun Facts

- Debut: 2004
Expand Down
26 changes: 26 additions & 0 deletions archive/s/scala/factorial.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Scala Program to calculate
// Factorial of a number

// Creating object
object GFG
{
// Iterative way to calculate
// factorial
def factorial(n: Int): Int = {

var f = 1
for(i <- 1 to n)
{
f = f * i;
}

return f
}

// Driver Code
def main(args: Array[String])
{ val m= args(0).toInt
println(factorial(m))
}

}