A simple Interactive C Program Using Scanf Function

Written by

C programming + scanf

star Reading data From Keyboard

scanf(“control string”, &variable01, &variable02, …);

=> The ampersand symbol, &, is very important. It’s an operator specifying the variable name’s address. Omitting it, might result into unexpected results.

star How Does Scanf Behave During Execution

Consider: scanf(“%d”, &number);

=> This statement halts execution and waits for a value to be entered. That value will be stored in a variable ‘number‘ and is of type ‘integer‘ as specified by the format specifier ‘%d
=> The compiler will proceed once a number is typed in and the ‘Return‘ key is pressed.

star The Code At Work

PROGRAM:

//include your libraries here..
void main()
{
int number;

printf(“Enter an integer: \n”);     //prompt message
scanf(“%d”, &number);                 //read message

printf(“The number you entered is: %d”, number);
}

OUTPUT:

Enter an integer:
25
The number you entered is: 25

That’s it, a very simple program to keep things simple for you to understand how interactivity works. Do use the comment form below to add your part..

bulb Other C Programming Articles:
=> Random Numbers in C programming
=> It’s Too Easy To Make This Simple, But Worse, Logical Error In Programming



Posted in: World Of Programming

  (3) Responses to "A simple Interactive C Program Using Scanf Function " - Say your part!

  1. 1
    From bapunNo Gravatar   on October 25th, 2010 at 5:53 pm

    this post is ver useful i have learn a lot from this post.thanx

  2. 2
    From B.R.ArvindNo Gravatar   on February 2nd, 2011 at 7:28 pm

    nice job done………its useful..

  3. 3
    From jamaicaNo Gravatar   on August 4th, 2011 at 3:34 pm

    its so useful thanks so much . God Bless :)

Use The Form Below To Leave Your Comment(s):

Feel free to use these tags in your comments: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>