How to make program to print number entered by user in Turbo c and Code blocks (GCC Compiler)?

This programs takes the integer value entered by user and displays the same value as output. To store the entered value in a variable, we use the scanf() function in C Programming

Display the integer number entered by user

In this program, we have declared an integer variable num. The program prints a message on the screen, then user enters the integer number. The program then stores that entered value in variable num. Later we are displaying the value of variable num using printf() function.

#include <stdio.h>
int main()
{
   int num;
   /* The printf() functions is used for displaying
    * the message or output on the screen. Here we
    * are displaying a message for the user.
    *
    */
   printf("Enter a number: ");

   /* Here scanf() function reads the integer value
    * entered by user and stores it into the variable
    * num
    */
   scanf("%d", &num);

   // displaying the value of num using printf
   printf("The number entered by user is: %d", num);
   return 0;
}

Output:

Enter an integer: 10
The number entered by user is: 10

Recommended Book Must Buy :

To improve your skill and Knowledge you must read Let Us C 16TH EDITION  because this book is totally recommended for beginners and you can improve your skills by attempting example and question inside it 

Note : If you want this book with solution . what you have to do is to click here 

Post a Comment

0 Comments