how to print a decimal in c code example

Example 1: how print fload wiht 3 decimal in c++

#include <iostream>
#include <cstdio>
using namespace std;

int main() 
{
    // This code helps you to print a number with desired decimal
    double Number=10.3454;
    printf("%.3lf",Number);

    return 0;
}

Example 2: print double in c

#include<stdio.h>

int main()
{
    double d = 123.32445;

    //using %f format specifier
    printf("Value of d = %f\n",d);

    //using %lf format specifier
    printf("Value of d = %lf\n",d);

    return 0;
}

Tags:

Cpp Example