知识点:
- 整型:基本整型:int,短整型:short,长整型:long ;
- 浮点型:单精度浮点型:float,双精度浮点型:double ;
- 字符型:char:一个字符,占用一个字节 。
其中,数据类型对象的取值范围取决于具体的机器,但是取值大小排序是一定的,为:
char ≤ short ≤ int ≤ long ≤ float ≤ double。
任务:
定义变量,并为变量赋值。
要求:
定义一个整型变量为 a,为变量 a 赋值5;定义一个单精度浮点型变量 b,为其赋值2.1。输出格式如下表示:
整型变量值:5
单精度浮点型变量值:2.100000
测试输入:无
预期输出:
整型变量值:5
单精度浮点型变量值:2.100000
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=5;
float b=2.1;
printf("整型变量值:%d\n",a);
printf("单精度浮点型变量值:%0.6f",b);
return 0;
}