C Program To Print an Integer (Entered by the User)

In this post, we are going to Write a C Program To Print an Integer (Entered by the User).

The integer entered by the user is stored in a variable and printed on the screen.

C Program To Print an Integer (Entered by the User)

So, Without further ado, let’s begin the tutorial.

C Program To Print an Integer

// C Program To Print an Integer
#include <stdio.h>
int main(){
    int num;
    // Display Message to Take Input
    printf("Enter an Integer: ");
    // Takes input from the User
    scanf("%d", &num);
    // Displays Output
    printf("The Entered Integer is: %d", num);
    return 0;
}

Output

Enter an Integer:18
The Entered Integer is: 18

How Does This Program Work ?

  int num;

In this program, we have declared an integer named num.

  scanf("%d", &num);

The input is taken by using scanf() function, the integer is stored in the num variable.

  printf("The Entered Integer is: %d", num);

Then, the value stored in the num variable is displayed on the screen using printf() function.

Some of the used terms are as follows:

#include <stdio.h> – In the first line we have used #include, it is a preprocessor command that tells the compiler to include the contents of the stdio.h(standard input and output) file in the program.

The stdio.h is a file which contains input and output functions like scanf() and printf() to take input and display output respectively.

Int main() – Here main() is the function name and int is the return type of this function. The Execution of any Programming written in C language begins with main() function.

Scanf() – Scanf() function is used to take input from the user. Here %d indicates that we are reading decimal/integer type.

printf() – printf() function is used to display and print the string under the quotation to the screen.

// – Used for Commenting in C

Conclusion

I hope after going through this post, you get to know how to write a c program to print an Integer (entered by the user).

If you have any doubt regarding the program, let us know in the comment section. We will be delighted to help you.

Also Read:

1 thought on “C Program To Print an Integer (Entered by the User)”

Leave a Comment

Your email address will not be published.