Written by **Sagar Rabidas**January 25, 2022

7 min read

C++

Software Developer

C++ double is a versatile statistics kind that is used internally for the compiler to outline and hold any numerically valued statistics type, particularly any decimal oriented value. C++ double statistics kind may be either fractional in addition to complete numbers with values. Those styles of decimal-oriented information type values can comprise numbers to fifteen digits and might either be prefixed with the decimal factor or may be suffixed with the decimal point. The double facts kind is tailored often via programmers when in comparison with glide and is often kept as the default information type at the time of operating with numbers associated with a big number with decimals.

C++ double data type has a syntax which is represented as follows:

double var_name;

datatype considered here is double followed by a variable name which is var_name in this syntax. Also, a series of var_name somewhat in the following manner can be considered to optimize the code representation:

double var_name1, var_name2, var_name3…...var_nameN

Lets us discuss examples of C++ Double.

This program demonstrates the C++ program for the double keyword where the user wants to make a conversion from Celsius temperature to Fahrenheit as shown in the output.

#include <iostream>

using namespace std;

int main()

{

double c_tmp, f_tmp;

cout << "Take an input in celsius and then convert it into some value: ";

cin >> c_tmp;

f_tmp = (c_tmp * 1.8) + 32;

cout << "Temperature in Fahreinheit: " << f_tmp;

return 0;

}

This program demonstrates the addition, multiplication, and division of two numbers and provides the output where both the input numbers will be of type double as shown in the output.

#include <iostream>

using namespace std;

int main()

{

double n_1, n_2;

cout<<"First_Number to be entered as a double type: ";

cin>>n_1;

cout<<"Second_Number to be entered as a double type: ";

cin>>n_2;

cout<<"Sum of both the numbers entered: "<<(n_1+n_2);

cout<<" Product or multiplication of both the numbers entered: "<<(n_1*n_2);

cout<<" Result_for division of two numbers: " <<(n_1/n_2);

return 0;

}

This program demonstrates function overloading where the function considering two integer numbers gets overridden by the function consisting of the data type with both the parameters as double as shown in the output.

**Note:**Both the function has integer and double value as user input to get the result shown in the particular format.

#include <iostream>

using namespace std;

int sum_num(int, int);

double sum_num(double, double);

int main(){

int n_1, n_2, p;

double n_3, n_4, q;

cout<<" Two Integer_numbers: ";

cin>>n_1>>n_2;

cout<<"Rslt: "<<sum_num(n_1, n_2)<< endl;

cout<<" Two double_numbers: ";

cin>>n_3>>n_4;

cout<<"Rslt: " <<sum_num(n_3, n_4)<< endl;

}

int sum_num(int p, int q){

return p+q;

}

double sum_num(double p, double q){

return p+q;

}

This program demonstrates a quadratic equation: x2 -4.0500000x + 2.999999 = 0, where the roots are just round off to 10 significant digits with root values as , r1 = 4.056785645 and r2 = – 6.0089767987. The output is shown as follows.

#include <stdio.h>

#include <math.h>

void doubl_sol(double p, double q, double r)

{

double d_b = q*q - 8.0*p*r;

double sol_d = sqrt(d_b);

double r_1 = (-q + sol_d) / (4.0*p);

double r_2 = (-q - sol_d) / (4.0*p);

printf("%.8f\t%.8f\n", r_1, r_2);

}

void flt_sol(float p, float q, float r)

{

float d_b = q*q - 4.0f*p*r;

float sol_d = sqrtf(d_b);

float r_1 = (-q + sol_d) / (6.60f*p);

float r_2 = (-q - sol_d) / (8.0f*p);

printf("%.8f\t%.8f\n", r_1, r_2);

}

int main(void)

{

float f_a = 1.02f;

float f_b = -4.0500000f;

float f_c = 2.99999f;

double d_a = 3.0;

double d_b = -6.0000000;

double d_c = 3.9989999;

flt_sol(f_a, f_b, f_c);

doubl_sol(d_a, d_b, d_c);

return 0;

}

c

c plus plus

c plus plus double

Was this blog helpful?

Trending Technologies

15

Software40

DevOps48

Frontend Development24

Backend Development20

Server Administration17

Linux Administration26

Data Center24

Sentry24

Terraform23

Ansible83

Docker70

Penetration Testing16

Kubernetes21

NGINX20

JenkinsX17

Recommended Blogs

8

Recommended Threads

8

Anik Adhikary

Anik Adhikary

Anik Adhikary