Home »
Code Snippets »
C/C++ Code Snippets
C program to read and print large integer number.
By: IncludeHelp, On 26 OCT 2016
In this c program, we will learn how to handle large integer numbers - here we are going to learn how to read and print large integer number in c programming language?
To achieve this we are using a data type (combination of data type and qualifiers) unsigned long long int to declare variable, read value and print.
Format specifier for unsigned long long int type of variable
We can read and print unsigned long long int type values using "%llu" - here l for long and u for unsigned.
In this example, we are declaring two variables a and b, a is unsigned int type and b is unsigned long long int type.
We will provide the same values (987654321012345678) to both variable, a will truncate the value but b is able to store this large value.
C program - Read and Print Large Integer Number
Let’s consider the example
/*C program to read and print large integer number*/
#include <stdio.h>
int main()
{
unsigned int a=0;
unsigned long long int b=0;
printf("Enter value of a: ");
scanf("%u",&a);
printf("Enter value of b: ");
scanf("%llu",&b);
printf("a=%u\n",a);
printf("b=%llu\n",b);
return 0;
}
Enter value of a: 987654321012345678
Enter value of b: 987654321012345678
a=1154616142
b=987654321012345678