Specified Number of Decimal Points for floating Values

 Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    float ft=12.4466;
    double db=1234.56789;
    clrscr();
    printf("Float=%f",ft);
    printf("\nDouble=%lf",db);
    printf("\nFloat=%.2f",ft);
    printf("\nDouble=%.2lf",db);
    getch();
}

Output:

Float=12.446600
Double=1234.56789
Float=12.44
Double=1234.56

Definitions :

#include<stdio.h> :

                It is a preprocessor file which include the header file of stdio.h(standard input output ) header file. In these header file contains the functions of printf(), scanf(), etc.,

#include<conio.h> :

                It is a preprocessor file which include the header file of conio.h(console input output ) header file. In these header file contains the functions like clrscr(), getch(), etc.,

void main(){} :

                In these Main function we can write our entire program with statements.

                void => It tell is an Empty argument

printf   :      

   It is a function and is  used to print data on the standard output device (monitor).


float : 

The numbers which are stored in the form of floating point representation is called
 as float data type.
     Eg: 10.25, 478.1234, -56.37821, etc.

double : 

The numbers which are stored in the form of double precision floating point representation is called as double data type.
      Eg: 1023.56789, 12345.3672, 0.456321, -567.4556 etc.
Note :
           void :   Empty Data type

clrscr() :

                This function clears the console screen of any previous outputs so that the output of the program currently executed alone is visible on the console screen.

getch() :

                 The function getch() basically stands for "get character". The getch() function is usually used to hold the output screen until the user presses on the keyboard i.e., the case of pressing key to continue.


Next Topic        :  Constants

No comments:

Post a Comment