forked from seeditsolution/cprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request seeditsolution#255 from Ankit-07-17/patch-1
Factorial_of_a_number
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
int main() { | ||
int n, i; | ||
unsigned long long fact = 1; | ||
printf("Enter an integer: "); | ||
scanf("%d", &n); | ||
|
||
// shows error if the user enters a negative integer | ||
if (n < 0) | ||
printf("Error! Factorial of a negative number doesn't exist."); | ||
else { | ||
for (i = 1; i <= n; ++i) { | ||
fact *= i; | ||
} | ||
printf("Factorial of %d = %llu", n, fact); | ||
} | ||
|
||
return 0; | ||
} |