take long long input in c
To take a long long
input in C, you can use the scanf
function with the %lld
format specifier. Here's an example code snippet that demonstrates how to do this:
#include <stdio.h>
int main() {
long long num;
printf("Enter a long long number: ");
scanf("%lld", &num);
printf("You entered: %lld\n", num);
return 0;
}
Let's break down the code and explain each step:
First, we include the necessary header file
stdio.h
, which provides the standard input/output functions likeprintf
andscanf
.Then, we define the
main
function, which is the entry point of a C program.Inside the
main
function, we declare a variablenum
of typelong long
, which can hold large integer values.We use
printf
to display a prompt message asking the user to enter along long
number.The
scanf
function is used to read the input from the user. We pass the%lld
format specifier to indicate that we are expecting along long
input. The&
operator is used to get the address of thenum
variable, so thatscanf
can store the input value at that address.After reading the input, we use
printf
to display the entered value using the%lld
format specifier.Finally, we return 0 to indicate successful program execution.
By following these steps, you can take a long long
input in C using the scanf
function.