Print an integer in C language: a user inputs an integer, and we print it. Input is done using scanf function, and the number is printed on screen using printf.
C priogram to print an int (integer)
printf("Enter an integer\n");
printf("The integer is: %d\n", a);
Output of the program:
C program to print first hundred positive integers [1, 100] using a for loop:
for (c = 1; c <= 100; c++)
printf("%d ", c);
In C language, we have data types for different types of data, for integers, it's int, for characters it's 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 that 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 display it.
C program to store an integer in a string
int main ()
printf("Input an integer\n");
Output of program:
An advantage of using a string is that we can store huge integers, but we can't perform arithmetic operations directly; for this, you can create functions. C programming language does not have a built-in data type for such numbers.