How to teach C to a violinist (Part III)
Posted by jayzeegp en julio 15, 2008
In order to do this we will use scanf function.
We will use it to receive an integer via keyboard and “write” it into a variable that we created previously.
Syntax to ask for an integer and store it in the variable called “raf”:
I think it is easy to see that %d is the same that we did on printf, it just says that our program is waiting for an integer number. The & symbol is a thing a little bit complex to explain right now, so we will think it just says “save the number here”, and then, you put the name of the variable.
printf(“Insert a number\n”);
This program will just wait for the user to insert a number via keyboard and will save it on variable a.
I think I understood! Give me more exercises!
1.-Modify the example above to make it say “The number you entered was X”, where X is the number stored in a.
2.-Make a program which ask the user for two numbers and prints the result of multiplying them on screen.