根据提示,在右侧编辑器中的 Begin-End 之间补充代码。定义3个有符号整型变量,分别为短整型、基本整型、长整型;定义3个无符号整型变量,分别为短整型、基本整型、长整型;定义3个浮点型变量,分别为单精度、双精度、长双精度;定义2个字符型变量,分别为有符号字符型,和无符号字符型;从键盘 ( 控制台 ) 获取这11个变量的值,并输出,其中长双精度浮点数保留3位小数。希望通过程序的编写和执行深入体会不同数据类型在定义、输入输出、取值范围等方面的异同。输入输出格式详见测试说明。
时间: 2023-05-13 10:04:38 浏览: 324
下面是代码:
```c++
#include <iostream>
using namespace std;
int main() {
short s;
int i;
long l;
unsigned short us;
unsigned int ui;
unsigned long ul;
float f;
double d;
long double ld;
char c;
unsigned char uc;
cout << "请输入一个 short 型整数:";
cin >> s;
cout << "short 型整数为:" << s << endl;
cout << "请输入一个 int 型整数:";
cin >> i;
cout << "int 型整数为:" << i << endl;
cout << "请输入一个 long 型整数:";
cin >> l;
cout << "long 型整数为:" << l << endl;
cout << "请输入一个 unsigned short 型整数:";
cin >> us;
cout << "unsigned short 型整数为:" << us << endl;
cout << "请输入一个 unsigned int 型整数:";
cin >> ui;
cout << "unsigned int 型整数为:" << ui << endl;
cout << "请输入一个 unsigned long 型整数:";
cin >> ul;
cout << "unsigned long 型整数为:" << ul << endl;
cout << "请输入一个 float 型浮点数:";
cin >> f;
cout << "float 型浮点数为:" << fixed << setprecision(3) << f << endl;
cout << "请输入一个 double 型浮点数:";
cin >> d;
cout << "double 型浮点数为:" << fixed << setprecision(3) << d << endl;
cout << "请输入一个 long double 型浮点数:";
cin >> ld;
cout << "long double 型浮点数为:" << fixed << setprecision(3) << ld << endl;
cout << "请输入一个 char 型字符:";
cin >> c;
cout << "char 型字符为:" << c << endl;
cout << "请输入一个 unsigned char 型字符:";
cin >> uc;
cout << "unsigned char 型字符为:" << uc << endl;
return 0;
}
```
测试说明:
输入格式:
- short 型整数
- int 型整数
- long 型整数
- unsigned short 型整数
- unsigned int 型整数
- unsigned long 型整数
- float 型浮点数
- double 型浮点数
- long double 型浮点数
- char 型字符
- unsigned char 型字符
输出格式:
- short 型整数为:s
- int 型整数为:i
- long 型整数为:l
- unsigned short 型整数为:us
- unsigned int 型整数为:ui
- unsigned long 型整数为:ul
- float 型浮点数为:f
- double 型浮点数为:d
- long double 型浮点数为:ld
- char 型字符为:c
- unsigned char 型字符为:uc
其中,s、i、l、us、ui、ul、f、d、ld、c、uc 分别为输入的变量值。