--------------------------------------------------------------------------------------------------
What is scanf function ?
What is scanf function ?
scanf() is a function, Which is use in the C
programming language for scanning any output that given by user or
programmer.
It is an predefined function in the
stdio.in header file.
From the user for taking any input scanf () function used.
--------------------------------------------------------------------------------------------------
Syntax
of scanf function
?
Where,
%d = for data type of input (integer).
&a = memory location for input data.
--------------------------------------------------------------------------------------------------
How
to write scanf ()
function ?
Step
1:
Write scanf.
Step
2:
Write open parentheses " ( ".
Step
3:
Write %d for taking integer data, %c for
character, %f for float values in between " " (double inverted
comma).
Step
4:
Write comma (,) and after that &a and
close parentheses.
Step
5:
In last of scanf()
function, Write semicolons ; .
--------------------------------------------------------------------------------------------------
Program to Adding two numbers taking from users using scanf() function -
#include <stdio.h>
#include <conio.h>
int main ()
{
int a,b,sum;
int a,b,sum;
printf("Enter any two numbers : ");
scanf("%d%d",&a,&b);
sum = a + b;
printf(""Addition of two numbers is : %d",sum);
getch();
return 0;
scanf("%d%d",&a,&b);
sum = a + b;
printf(""Addition of two numbers is : %d",sum);
getch();
return 0;
}
--------------------------------------------------------------------------------------------------
Commands to perform C program in Turbo C++
Create a new file : File > new.
save program : F2 > file_name.c
compile : Alt + F9
execute : Ctrl + F9
--------------------------------------------------------------------------------------------------
Commands to perform C program in Linux OS
Create a new file : Terminal > gedit file_name.c
save program : save
compile : gcc file_name.c
execute : ./a.out
--------------------------------------------------------------------------------------------------
Program to Adding two numbers taking from users using scanf() function in Turbo C++
Program to print Adding two numbers taking from users using scanf() function in Linux OS
Output in Linux OS
Thank You
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


