You are here

Print an integer in C

Print an integer in C language: a user will input an integer and it is then printed. Input is done using scanf function and number is printed on screen using printf.

C program to print an integer

#include <stdio.h>
 
int main()
{
  int a;
 
  printf("Enter an integer\n");
  scanf("%d", &a);
 
  printf("Integer that you have entered is %d\n", a);
 
  return 0;
}

Output of program:
Print an integer C program output

In C language we have data type for different types of data, for integer data it is int, for character it is char, for floating point data it's float and so on. For large integers you can use long or long long data type. To store integers which are greater than (2^18-1) which is the range of long long data type you may use strings. In the below program we store an integer in a string and then display it.

C program to store integer in a string

#include <stdio.h>
 
int main () 
{
   char n[1000];
 
   printf("Input an integer\n");
   scanf("%s", n);
 
   printf("%s", n);
 
   return 0;
}

Output of program:

Input an integer
13246523123156432123154131212341564313219
13246523123156432123154131212341564313219

Advantage of using a string is that we can store very large integers. C programming language does not have a built in data type to handle very large numbers.