Uses Of "scanf" function in C language.
scanf Function:
syntax of scanf: scanf(const char *format, Object *arg(s))
scanf if a function which is use for scan an input from user. scanf is a library function which in standard input output library. scanf is some ware like as prinf function. scanf function scan a input from an user via standard input (keyboard).
scanf function is derived from #include<stdio.h> library ( Standard input output libraries.)
Hear we will see some example of different type of value scan by scanf .
1) For integer Value scan.
Example :
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\nWelcome,CoderFact");
printf("\nEnter a number : ");
scanf("%d", &a);
printf("Your entered a number is : %d " , a);
getch();
}
OUTPUT ::
we pass 5 as input form keyboard and we can see scanned number as 5.
hear we use %d to scan an integer value. %d is a specifier that specify that the number is an integer. simply %d is stand for decimal integer number.
2) For character scan.
Example :
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
clrscr();
printf("\nWelcome,CoderFact");
printf("\nEnter a name : ");
scanf("%c", &a);
printf("Your entered a name is : %c " , a);
getch();
}
we pass 5 as input form keyboard and we can see scanned number as 5.
hear we use %d to scan an integer value. %d is a specifier that specify that the number is an integer. simply %d is stand for decimal integer number.
Example :
#include<stdio.h>
#include<conio.h>
void main()
{
char a[10];
clrscr();
printf("\nWelcome,CoderFact");
printf("\nEnter a name : ");
scanf("%s", &a);
printf("Your entered a name is : %s " , a);
getch();
}
Example::
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
printf("\nWelcome,CoderFact");
printf("\nEnter a float number : ");
scanf("%f", &a);
printf("Your entered a number is : %f",a);
getch();
}
OUTPUT::
Comments
Post a Comment