how to take big input in C

, ,

How to take input 10^18 in C

1 Like

long long int is there in C. you can take it as
scanf("%lld",&var);
its a 64 bit integer.

1 Like

long long int, long long, long all are long.

Use long int type and make sure you used %ld format in the scanf.

    long int l=0;
    scanf("%ld", &l);
  • “long long int” is best suitable.

    scanf("%lld",&input);

  • U can also use “unsigned long long int” if input is +ve always.

    scanf("%llu",&input);

You must use scanf("%I64d",&num);
i.e. %I64d for accepting long long int for newer version of operating systems. It is used in 64 bit integer.

I know how to use lld but
Out of curiosity What does LLD stand for?

1 Like

i think i have figured it out.
long long int so insted of %d we use %lld
thank you

Probably you can’t store a number upto the size 10^18 even in a long long int. You’d better take it as a string and change your algorithm accordingly.

A 32-bit unsigned int has a range from 0 to 4,294,967,295. 0 to 65535 would be a 16-bit unsigned. An unsigned long long (and, on a 64-bit implementation, possibly also ulong and possibly uint as well) have a range (at least) from 0 to 18,446,744,073,709,551,615 (2^64-1).

Maximum in C,
Data types- unsigned long long int
Range- 0 to 18,446,744,073,709,551,615
Format Specifier- %llu

1 Like

The maximum possible integer input can be taken in C using long long int. It has a range of −9,223,372,036,854,775,807 to +9,223,372,036,854,775,807. If you only deal with positive numbers then unsigned long long can be used which has a range of 0 to 18,446,744,073,709,551,615.

long long i;
unsigned long long j;
scanf ("%lld %llu",&i,&j); //Format specifier for long long int can also be %lli

In case of float double is used to take big inputs. It has a range of -1.7e4932 to +1.7e4932 in 32 bit compiler. Format specifier is %Lf.

Bigger inputs than this can be taken using strings.

you can use unsigned long long int for 10^18 range number

Try to use unsigned long long as assuming the value is positive it can hold up to
18,446,744,073,709,551,615.

how to read a number of 24 digits in c

take it in a char array