How to print float number in c language.
Floating numbers are basically real numbers.
if we want to print folat numbers in c language for that we have to take %f as keyword in printf and scanf function.
Example :
For scanning:
Scanf("%f",&variable name);
For printing:
Printf("foat num is %f.",variable name);
There are Diffrent formats to print float number in c language.
Hear we take 1 example which shows you that if we want to print 2 digit after "." Than we have to just write " .2 " in calling printf sattment.
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
printf("\nWelcome,CoderFact");
printf("\nEnter a number : ");
scanf("%f", &a);
printf("Your entered a number is : %.2f " , a);
getch();
}
OUTPUT::
Hear we pass value 12 and we get output
12.00 this thing is occur due to we take input as float number and pass in formation of ".2f" so it make output properly.
Hear we pass float number 12.23 and we get output 12.23
Hear we pass value 13.234 and we get output 13.23 this thing is occur due to ".2f" formation. This formation is allows only 2 number after "." Notation.
Comments
Post a Comment