Computer Concept & Programming In C - Unit II - 4

Showing the Numeric Values of the Characters: -
Like the character format specifier (%c) that is used to format a single character, (%d) called the integer format specifier, is used to format an integer.
The following program shows the numeric values of characters.
# include <stdio.h>
# include <conio.h>
void main ( )
  {
     char C1; 
     char C2;
     C1 = ‘A’;
     C2 = ‘a’;
      printf (“The numeric value of A is: %d.\n”, C1);
      printf (“The numeric value of a is: %d.\n”, C2);
      getch ( );
}
The output of the above program is 
The numeric value of A is: 65
The numeric value of a is: 97
(iii) The Float Data Type: -
(1) The floating point number is another data type in the C language. Unlike an integer number, a floating point number contains a decimal point. For example 5.831 is a floating point number and so are 3.02 and – 3.146. A floating point number is also called a real number.
A floating point number is specified by the float keyword in the C language.
(2) Floating point numbers can be suffixed with f or F to specify float.
(3) A floating point number without a suffix is double by default.
(4) Like an integer number, a floating point number has a limited range. The ANSI standard requires that the range be at least plus or minus 1.0 x 1037.
(5) Normally, a floating point number is represented by taking 32 bits.
(6) Therefore a floating point number in C is of at least six digits of precision. That is for a floating point number, there are at least six digits or decimal places on the right side of the decimal point.
(7) A floating point division produces another floating-point number.
(8) A floating point division is carried out if both the division and dividend or one of them are floating point numbers.
Declaring Floating Point Variables: -
The following shows a declaration format for a floating point variable:
  float <variable name>;
Similar to the character or integer declaration, if you have more than one variable to declare, you can use the format like this:
float <variable name 1>;
float <variable name 2>;
float <variable name 3>;
Alternative way.
float variablename 1, variablename 2, variablename3;
The Floating Point Format Specifier (%f): -
The following program prints out the result of the integer and Floating Point divisions.
# include <stdio.h>
void main ( )
  { 
int int_num1, int_num2, int_num3; /*Declare integer variables*/
float flt_num1, flt_num2, flt_num3; /*declare floating point variables*/
int_num1 = 32/10;            /*Both divisor and dividend are integers*/
flt_num1 = 32/10;
int_num2 = 32.0/10; /*The divisor is an integer*/
flt_num2 = 32.0/10;
int_num3 = 32/10.0; /*The dividend is an integer*/
flt_num3 = 32/10.0;
printf(“\n The integer division of 32/10 is %d”, int_num1);
printf(“\n The floating point division of 32/10 is %f ”, flt_num1);
printf(“\n The integer division of 32.0/10 is %d”, int_num2);
printf(“\n The floating point division of 32.0/10 is %f ”, flt_num2);
printf(“\n The integer division of 32/10.0 is %d”, int_num3);
printf(“\n The floating point division of 32/10.0 is %f ”, flt_num3);
}
The output of above program will be 
The integer division of 32/10 is: 3
The floating point division of 32/10 is: 3.000000
The integer division of 32.0/10 is: 3
The floating point division of 32.0/10 is 3.200000
The integer division of 32/10.0 is 3
The floating point division of 32/10.0 is 3.200000.
Explanation of program: -
Inside the main ( ) function the two statements declare three integer variables, int_num1, int_num2 and int_num3 and three floating point variables flt_num1, flt_num2 and flt_num3. 
Next, we assign the result of 32/10 to int_num1 and flt_num1, respectively; 32.0/10 to int_num2 and flt_num2 and 32/10.0 to int_num3 and flt_num3 respectively. 
The lines print out the values contained by three int variables and the three floating-point variables. Note that %d is used for the integer variables, and the floating point specifier (%f) is used for formatting the floating point variables in the printf( ) function.
Because the truncation occurs in the integer division of 32/10, flt_num1 contains 3.000000, not 3.20000, which you can see from the second line of the output. However, flt_num2 and flt_num3 are assigned 3.200000 because both 32.0/10 and 32/10.0 are considered as the floating-point division.  
But int_num2 and int_num3 as integer variables discard respectively the fraction part of the floating-point division of 32.0/10 and 32/10.0. Therefore you just see the integer 3 in both the lines below.