Skip to content

Simple command line tool to compute factorial of an integer and print it to standard output

Notifications You must be signed in to change notification settings

Naakinn/factorial-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

factorial CLI

Note:

The biggest unsigned integer type in C is unsigned long long(uint64_t) whose size is implementation-defined and othen is 64 bits. Thus this program can't compute factorial of a number bigger than 20(

When unsigned variable is assigned to a value bigger than it's type can hold, the value resets to 0, for instance

#include <stdio.h> /* for printf */
#include <stdint.h> /* for integer types and macro constants */

int main() {
    unsigned long long a = UINT64_MAX; /* max value */
    uint64_t b = UINT64_MAX; /* max value */

    printf("%lu\n", a);
    printf("%llu\n", b);

    ++a; 
    ++b;

    printf("%lu\n", a);
    printf("%llu\n", b);

    ++a;
    ++b;

    printf("%lu\n", a);
    printf("%llu\n", b);
}

produces

18446744073709551615
18446744073709551615
0
0
1
1

About

Simple command line tool to compute factorial of an integer and print it to standard output

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages