IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
Earn Free Bitcoin
CSimple Functions ❯ Factorial Calculator
<05.04>
/* The factorial function: one argument, one result */
#include <stdio.h> /* this function will return an integer */ int factorial (int n) { int i, product; product = 1; /* initialization */ /* computes n*n-1... */ for (i=n; i>1; i=i-1) { product = product * i; } /* the value that goes out */ return (product); } int main (void) { int a, result; printf ("Enter an integer number: "); scanf ("%d", &a); /* calling the function */ result = factorial (a); /* printing the report */ printf ("The factorial of %d is %d.\n", a, result); return (0); } /* NOTE: a large number (like 13) will produce an arithmetic overflow */
Hergestellt in Deutschland / Made in Germany
Enter an integer number: 4 The factorial of 4 is 24. Enter an integer number: 13 The factorial of 13 is 1932053504. The factorial of 13 is 6227020800. Error caused by arithmetic overflow.
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.