Last active
April 3, 2024 10:10
-
-
Save kehiy/cb79806aa4174bf366d06a865b2b0aa2 to your computer and use it in GitHub Desktop.
factorial calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int factorial(int n) { | |
if (n == 0) { | |
return 1; | |
} | |
return n * factorial(n -1); | |
} | |
int main() | |
{ | |
printf("%d", factorial(5)); // 5! = 120 | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func facto(n int) int { | |
if n == 0 { | |
return 1 | |
} | |
return n * facto(n - 1) | |
} | |
func main() { | |
f := facto(5) | |
fmt.Println(f) // 5! = 120 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun factorial (n) | |
(if (<= n 1) | |
1 | |
(* n (factorial (- n 1))))) | |
(factorial 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n: int): | |
if n == 0 : | |
return 1 | |
return n * factorial(n - 1) | |
print(factorial(5)) # 5! = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn factorial(n: i8) -> i8 { | |
if n == 0 { | |
return 1; | |
} | |
n * factorial(n - 1) | |
} | |
fn main() { | |
println!("{}", factorial(5)); // 5! = 120 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment