Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // Function to calculate factorial
- unsigned long long calculateFactorial(int number) {
- if (number == 0 || number == 1) {
- return 1;
- } else {
- unsigned long long factorial = 1;
- while (number > 1) {
- factorial *= number;
- number--;
- }
- return factorial;
- }
- }
- int main() {
- int num;
- printf("Enter a positive integer: ");
- scanf("%d", &num);
- if (num < 0) {
- printf("Factorial is not defined for negative numbers.\n");
- } else {
- unsigned long long result = calculateFactorial(num);
- printf("Factorial of %d = %llu\n", num, result);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement