如何定义整型变量 关键字:int 修饰符: short, long, unsigned 例 int num short int i ■ long int sum unsigned int count
11 如何定义整型变量 ◼ 关键字:int ◼ 修饰符: ◼ short, long, unsigned ◼ 例: ◼ int num ◼ short int i ◼ long int sum ◼ unsigned int count
整型数据 类型说明符位数数值范围 短整 short 16 32768~32767 基本 int 32231~(231-1) 长整 ong32231~(231-1) 无符号 unsigned short 16 0-65535 unsigned [int 32 0(232-1) unsigned long 32 0(232-1)
12 整型数据 类型 说明符 位数 数值范围 短整 short 16 -32768~32767 基本 int 32 -2 31~(231-1) 长整 long 32 -2 31~(231-1) 无符号 unsigned short 16 0~65535 unsigned [int] 32 0~(232-1) unsigned long 32 0~(232-1)
问题1:四则运算 程序要求 a随机产生两个整数(<10) ■进行加运算 输入运算结果 判断结果是否正确 13
13 问题1:四则运算 ◼ 程序要求: ◼ 随机产生两个整数(<10) ◼ 进行加运算 ◼ 输入运算结果 ◼ 判断结果是否正确
# include< cmath>//常用数学函数 int maino int a, b,sum;//定义整型变量 aranda%o10; b=rando%o10; cout<≤a<<+≤≤b<<= cIn>>sum; if(sum==a+b) cout≤<" correct<<end el se 请指出: cout<<" error!"<<endH常量和变量 数据类型
#include<cmath> //常用数学函数 int main() { int a, b, sum; //定义整型变量 a=rand()%10; b=rand()%10; cout<<a<<'+'<<b<<'='; cin>>sum; if(sum==a+b) cout<<"correct!"<<endl; else cout<<"error!"<<endl; } 请指出: 常量和变量 数据类型
问题2:已知半径计算 圆面积 ■球体积 圆周长 必须考虑: 数据类型、计算精度等
15 问题2:已知半径计算... ◼ 圆面积 ◼ 球体积 ◼ 圆周长 必须考虑: 数据类型、计算精度等