// create float and assign value
// print float value to console
#include <stdio.h>
int main()
{
float pi = 3.14;
float dollars;
dollars = 32.27;
printf("I have %f dollars", dollars);
// controls the number of numbers shown after the decimal point
printf("
I have %0.2f dollars", dollars);
//get a float from user
//print float value to console
#include <stdio.h>
int main()
{
//define a float variable
float a;
//print the prompt
printf("Please enter a float number: ");
//Actually getting the number
scanf("%f", &a);
printf("You have entered %f", a);
}
#include <stdio.h>
int main (){
float a;
printf("
Enter a real number here please: ");
scanf("%f",&a);
printf("
Printing Number with different precision: ");
printf("
Number default precision: %f", a);
printf("
Number in (0 d.p.): %.0f", a);
printf("
Number in (1 d.p.): %.1f", a);
printf("
Number in (2 d.p.): %.2f", a);
printf("
Number in (3 d.p.): %.3f", a);
printf("
Number in (3 d.p.): %.4f", a);
return 0;
}
float: It is used to store decimal numbers (numbers with floating point value) with single precision. double: It is used to store decimal numbers (numbers with floating point value) with double precision.
A float is a number with a decimal point.
float variable;
Code Example |
---|
C :: how to delete virtual hard disk virtualbox |
C :: fgets function in c |
C :: c string to int |
C :: c int to char |
C :: read from stdin c |
C :: celsius to fahrenheit formula |
C :: C Arithmetic Operators |
C :: number of hours, minutes, and seconds given the number of seconds. |
C :: ** in c |
C :: fwrite in c |
C :: how to convert int in to const char in c |
C :: c strstr |
C :: solana-test-validator log |
C :: c programming |
C :: convert string to int c |
C :: c break statement |
C :: How to copy one string into another in C |
C :: Initialization of a 3d array in c |
C :: pointer arithmetic on Arrray in c |
C :: yum install supervisor amazon linux |
C :: redis service |
C :: scopes in c |
C :: pointer in c |
C :: c read file from command line |
C :: Number 10 |
C :: powershell some fonts like #include are dissapearing |
C :: Fibonacci program c pthread |
C :: Uri/Beecrowd problem no - 1151 solution in C |
C :: temperature sensor data |
C :: Macro definition and expansion |