What is the largest data type for storing (and printing) an integer?

孤人 提交于 2019-12-05 04:16:57
wnoise

Your question is a bit unclear, but intmax_t is the largest signed integer-valued type (and uintmax_t is the largest unsigned integer type). These are typedefs defined in <stdint.h>, but if you are printing them, you need <inttypes.h> instead, and the PRInMAX macros for various values of n.

Without beating around the bush I would like to say that sometimes not in actual coding practice bt yes defintly in some competitions one might need very big data types bt I think we can do this. Why not take the entire sequence in the form of string and then use the atoi function to get the integer value it is I think politcally correct :: :)

#include<stdio.h>
#include<stdlib.h>

int main ()
{
    int i;
    char bigString [256];

    printf ("Enter a number: ");
    fgets (bigString, 256, stdin);

    i = atoi (bigString);
    printf ("The value entered is %d.",i);

    return 0;
}

In ISO C99 long long is at least 64bit which is the largest standard integer data type. It also comes as unsigned long long. Apparently your compiler might provide larger types wich defined by intmax_t and uintmax_t.

However based on your comments you might be looking for a bigint library like GMP. It allows for arbitrary long integers (and floating point) limited in length only by your system resources.

The data type with the longest printed string is a signed data type, unless you have an integer type that has a maximum unsigned value that is one digit longer than the maximum signed value.

For example, a 4-bit integer unsigned would be at most two characters unsigned or one character plus the negative sign when signed.

So, you should pick a signed data type to represent the largest printed string. Which should be long long.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!