TECHASHUS - BASIC PROGRAM FOR PRINTING INTEGERS IN C
This c program ask user to input an integer and then prints it. Input is done using scanf function and number is printed on screen using printf.
CODE:
#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:
Enter an integer
99
Integer that you have entered is 99
In c language we have data type for
different types of data, for integer data it is int,for characterdate char, for
floating point data it's float and so on. For large integersyou can use long or
long long data type. To store integers which are greater than 2^18-1which is
the range of long long data type you may use strings. In the below code we
store aninteger in a string
and then display it.
#include <stdio.h> int main () { char n[1000]; printf("Input an integer\n"); scanf("%s", n); printf("%s", n); return 0; }
Input an integer
13246523123156432123154131212341564313219
13246523123156432123154131212341564313219
Advantage of using string is that we can store very very large integers. C programming language does not has a built in type to handle large numbers.
No comments: