Subscribe Us

Scanf( ) function in C programming-C library function Scanf( ) - smartduniya

 In this blog I will be talking about how to use Scanf( ) function in c programming . Scanf( ) is  a c library function. Basically it is use to take input from user in programming. 

 

scanf() function in c

To  scan any thing  write this function on c programming for the standard input.

The first part of basic structure of c program then you will know that the first section in c program is documentation section and it is an optional section. There is no any rule like if you do not document our source code then it will not work, but since it is considered to be good practice to have source code documented, lets have this section included.

Scanf () function in c :

Now let's proceed to the syntax of scanf() function. So this is the syntax for scanf () function and since I don't want this syntax to be compiled, I'm goanna comment it and I have already taught you in my past post named "commenting  In C" that how to comment the statements in programming.

Let's learn scanf function through a problem . 

problem : Add Two numbers  , numbers are input by the keyboard ?

solution :Let's suppose you want to add 8 and 9 (8+9). In this type of problem how you tell to the compiler that you give as input and it's add with other input . For this First you have to scan the first input and next  scan second number . Then Add two input and output the result .

let's go to the program,

 

#include <stdio.h>

int main()

{

    /* code for add two number  */

 int a, b,c;

   printf("Type first number : "); 

   scanf("%d",&a); // scanf is use to take 'a' input from the user and store 

    printf("Type second number : "); 

   scanf("%d",&b); // scanf is use to take 'b' input from the user and store

   c =a+b;

   printf("%d + %d = %d",a,b,c);

 return 0;

}  .


If  you run the program, Asked to input first number and then asked to input second number. You have to input first number and second number and press enter out will get the result.   

Go to the out put of our program 

addition of two number






Related Post :

Post a Comment

0 Comments