Created
August 1, 2022 12:43
-
-
Save viraatmaurya/ebbb7db704cbdbf069fc9b09789565ad to your computer and use it in GitHub Desktop.
Large Factorials (code wars) in C language.
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
include<stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char const *argv[]) | |
{ | |
factorial(5); | |
return 0; | |
} | |
char *factorial(int n) | |
{ | |
if (n < 0) | |
{ | |
return ""; | |
} | |
unsigned long long int fact = 1; | |
for (int i = 1; i <= n; i++) | |
{ | |
fact *= i; | |
} | |
char *result = malloc(sizeof(char) * 100); | |
sprintf(result, "%llu", fact); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment