Inputting Real Number
Inputting Real Number
The field width of real numbers is not to be specified and therefore scanf() reads real numbers using the simple specification %f for both the notification.
Example:
Scanf(“%f%f”, &x, &y);
With input data 475.15 43.21
Wi475.15 to x
43.21 to y
Example: write a program to take input of float number (prog5.c)
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
clrscr();
printf("Enter two numbers");
scanf("%f%f",&a,&b);
printf("value of a=%f and b=%f",a,b);
getch();ll assign the values:
Output: entre two number of 12.15
34.5555
Velue of a=540000 and b=34.555500
Inputting character strings:
A scanf() function can input strings containing more than one
character.
Syntax:
%ws OR %wc
Here %c is used to read a single character.
%s is used to read word.
Example:
Write a program for take input of character (prog4.c)
#include<stdio.h>
#include<conio.h>
void main()
{
char c;
clrscr();
printf("Enter character");
scanf("%c",&c);
printf("Inputted character is %c\t",c);
getch();
}
Output:
Enter character H
Inputing character is H
Example:
Write a program for take input of string
#include<stdio.h>
#include<conio.h>
void main()
{
char c[20];
clrscr();
printf("Enter string");
scanf("%s",&c);
printf("Inputted string is \t %s",c);
getch();
}
Output:
Enter string heta
Inputing string heta
Comments
Post a Comment