Created
January 7, 2026 16:51
-
-
Save kms0219kms/9308c61e06c901299ec252ee1c67707d to your computer and use it in GitHub Desktop.
2025-2026 오성고_공동교육_정보과학 Day 3
This file contains hidden or 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
| import time | |
| def factorial_iter(n): | |
| result = 1 | |
| for i in range(1, n + 1): | |
| result *= i | |
| return result | |
| def main(): | |
| n = int(input("Enter a number: ")) | |
| start = time.perf_counter() | |
| print("Result:", factorial_iter(n)) | |
| end = time.perf_counter() | |
| print(f"Iterative({n}): {end - start:.6f} seconds") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or 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
| import time | |
| import math | |
| def main(): | |
| n = int(input("Enter a number: ")) | |
| start = time.perf_counter() | |
| print("Result:", math.factorial(n)) | |
| end = time.perf_counter() | |
| print(f"math.factorial({n}): {end - start:.6f} seconds") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or 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
| import time | |
| def factorial_rec(n): | |
| if n <= 1: | |
| return 1 | |
| return n * factorial_rec(n - 1) | |
| def main(): | |
| n = int(input("Enter a number: ")) | |
| start = time.perf_counter() | |
| print("Result:", factorial_rec(n)) | |
| end = time.perf_counter() | |
| print(f"Recursive({n}): {end - start:.6f} seconds") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment