-
-
Save darkf/1508707 to your computer and use it in GitHub Desktop.
sum digits of factorial with double in C
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
/* sums the digits of the factorial 10 (since not much larger can be held by a double) | |
copyright (c) 2011 darkf | |
use for anything, CC-0 or public domain etc */ | |
#include <stdio.h> | |
#include <string.h> | |
double f(int n){return !n?1:n*f(n-1);} | |
int g(char* b){int x=0,i;for(i=0;i<strlen(b);i++)x+=b[i]-'0';return x;} | |
main(){char b[256];double x=f(10);sprintf(b,"%.0f",x);printf("%d",g(b));} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment