Created
July 9, 2018 14:10
-
-
Save lalabuy948/9cae545fdfc49ca66a08289008403bdc to your computer and use it in GitHub Desktop.
Computes the factorial of number 'n' in c-lang
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){ | |
int a = 1; | |
for (int i = 1; i <= n; ++i) { | |
a *= i; | |
} | |
return a; | |
} | |
int main() { | |
printf("Please enter the positive integer:"); | |
int n; | |
while (scanf("%d", &n) != EOF) { | |
if (n > 0) { | |
printf("Factorial is: %d", factorial(n)); | |
printf("\n"); | |
} else { | |
printf("Please, enter positive number"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment