Differences:
Variables used in a program must be declared before using
them
Every C statement must be terminated with a semicolon (;)
A C program must be placed within the structure that is the
main( ) function.
Need of accepting data from the console input device
(Keyboard)
The above program adds only two numbers that is 45 and 50.
If we want to add any other numbers then, the program must be modified. Say for
example we want to add 125 and 256 then; the program must be modified as.
We need to modify the program every time need to add two
different numbers.
Need of scanf( ):
It is not a good practice to change the program, whenever
input to the program need to change.
Scanf( ) is a function used to accept the data from the user
while executing the program.
Different inputs can be given for different executions
without changing the program.
The scanf accepts the data from the user and stores into the
specified variables
In scanf the representation characters and the addresses of
variables must be specified.
Syntax:
|
Example:
Example explained:
During the run-time scanf( ) prompts and accepts the number
from user and stores into the variable x
Example:
0 comments:
Post a Comment