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
C programming code
#include <stdio.h> int main() { int a; printf("Enter an integer value\n"); scanf("%d", &a); printf("Integer that you have entered is %d\n", a); 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
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 <stdio.h> int main () { char n[1000]; printf("Input an integer\n"); scanf("%s", n); printf("%s", n); getch(); 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.
Subroto Mondal
Latest posts by Subroto Mondal (see all)
- Installing and Configuring OpenShift: A Step-by-Step Guide for Linux Experts with Terminal Code - February 19, 2023
- Sed Command in Linux with Practical Examples - February 19, 2023
- Rsync Command uses with examples - February 19, 2023