C中的浮点和双精度

浮动

浮点数是一种数据类型,用于表示浮点数。它是一个32位IEEE 754单精度浮点数(符号1位,指数8位,值23 *位。精度为6个十进制数字。

这是C语言中float的语法,

float variable_name;

这是C语言中的float的示例,

示例

#include<stdio.h>

#include<string.h>

int main() {

   float x = 10.327;

   int y = 28;

   printf("The float value : %f\n", x);

   printf("The sum of float and int variable : %f\n", (x+y));

   return 0;

}

输出结果

The float value : 10.327000

The sum of float and int variable : 38.327000

Double也是一种数据类型,用于表示浮点数。它是该值的64位IEEE 754双精度浮点数。它的精度为15个十进制数字。

这是C语言中double的语法,

double variable_name;

这是C语言中double的示例,

示例

#include<stdio.h>

#include<string.h>

int main() {

   float x = 10.327;

   double y = 4244.546;

   int z = 28;

   printf("The float value : %f\n", x);

   printf("The double value : %f\n", y);

   printf("The sum of float,


   double and int variable : %f\n", (x+y+z));

   return 0;

}

输出结果

The float value : 10.327000

The double value : 4244.546000

The sum of float, double and int variable : 4282.873000

以上是 C中的浮点和双精度 的全部内容, 来源链接: utcz.com/z/322509.html

回到顶部