Scanf In C
scanf
printf has now become our friend. printf is a “function” i.e. a statement that prints some texton the screen. Similarly, scanf is also a “function” used to take input from the keyboard.
scanf statement looks a lot like printf statement.
Syntax:
Note %d << If you've created variable integer use %d, if character use %c, if float use %f, Note the "&" ampersand operator use to point variables address
scanf("%d", &variablename);
Example#1:
/* Ask user age and display message */ #includeint main() { int age = 0; printf("Enter your age : "); /* Asking user age */ scanf("%d" , &age); /* taking input from user. Note the & operator */ printf("\n You are %d years old", age); return 0; }