Taking User Input

In C, we can use scanf function to take input from the user.

Point: When we take input from the user, we have to store it in a variable.

What we are doing in our example;

  • Declared int type variable age first
  • Prompting user to enter age.
  • Taking input and storing in age variable.
  • Printing value in age variable with some text.
  • Returning from the main function.

Taking Different types of Variables as Input

Till now, we konw that how to take input in int type variable. In this example, we will see that how can we take input in variables with different data types and printing them.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min