How to take User Input in C Programming Language

  • Add this line in the beginning of your code #include<stdio.h> to include standard input output header file.
  • Use scanf() functionin your code as mentioned below, Here %d is format specifier for integer data type and & is ampersand operator. Whatever integer as a input would be given by the user will be stored where ? answer to this question is given by ‘&’, it specifies the address where the user input is to be stored.
  • To see what user input was use printf() function.
  • Now open the command prompt to compile the program using command – gcc file_name.c
  • Then a executable file will be generated, just mention its name(in my case it was ‘a’).
  • Then it will ask for user input which is indicated by blinking underscore. Give your input and press ENTER.

Leave a Reply

Your email address will not be published. Required fields are marked *