C program print integer

Let’s talk about integers. Whole numbers less than zero are called negative integers. The integer zero is neither positive nor negative and has no sign. Two integers are opposites if they are each the same distance away from zero but on opposite sides of the number line. Positive integers can be written with or without a sign. Besides that, an integer without any sign is called Unsigned integer.

The int data type is signed and has a minimum range of at least -32767 through 32767 inclusive. The actual values are given in limits.h as INT_MIN and INT_MAX respectively.

An unsigned int has a minimal range of 0 through 65535 inclusive with the actual maximum value being UINT_MAX from that same header file.

C program print integer

This is a simple c program that takes value from the user and then prints it. Here input is done using scanf() function and print using stranded printf() function. <stdio.h> header file has the definition of scanf and printf function.

C programming code

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

 

Output of program:

Enter an integer value 10
Integer that you have entered is 10
press any key to continue.

looks like that

Print integer

In C language we have the data type for different types of data, for integer data it is int, for character data 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 code we store an integer in a string and then display it.

C program to store integer in a string

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

Output of program:

Input an integer
13246523123156432123154131212341564313219
13246523123156432123154131212341564313219

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

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.