The function used to get input
from the user during execution of program and stored in a variable of specified
form is called scanf() function.
Output
Example-Multiple Inputs:
#include<stdio.h>
Syntax:
scanf(“format string”,&
variable name);
format
string à format
specifier is written
& àaddress operator
& àaddress operator
Types:
- Single input e.g scanf(“%d”,&a);
- Multiple input scanf(“%d %c %d”, &a,&op,&b);
Example-Single
Input:
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
void main ()
void main ()
{
clrscr();
clrscr();
int a;
printf("Enter integar
value:");
scanf("%d",&a);
printf("The value you
enter = %d",a);
getch();
}
Output
Enter integer value:5
The value u enter is=5
The value u enter is=5
Example-Multiple Inputs:
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr();
int a, b;
printf("Enter two values
and operator:");
scanf("%d %d
%c",&a,&b,&op);
printf("Entered values =
%d %d %c",a,b,op);
getch();
}
Output:
Enter two values and operator:5 6 +
Output:
Enter two values and operator:5 6 +
Entered values =5 6 +
No comments:
Post a Comment