Floating Point Variables
Floating points represent numbers with decimals or they represent those numbers which have a fractional part attached to them for example, 10.2, -10.2 or 2.10. Floating point variables occupy 4 bytes of the computers memory and have a range of about 3.4 * 1038 to 3.4 * 1038. Figure 2.2 given below shows how floating variables are stored in the computers memory.
Figure 2.2: Storing floating variables
Program given below declares two floating variables ‘var1’ and ‘var2’ and displays them on the screen.
// Header File
# include <iostream.h>
// Main Function void main()
{
// Floating variables
float var1=-10.2;
float var2=10.2;
// Printing Variables
cout<<" Var 1:"<<var1; cout<<" Var 2:"<<var2;
}
No comments:
Post a Comment