求模运算符%是取余数的意思
重点::求模运算符只用于整数,不能用于浮点
计算有英石与磅数
#include<iostream>
using namespace std;
//一英石等于14磅
int main(void)
{
int t_stones; //total stone
int t_baskets=14; //Every basket of stones
cout<<"Enter your weight in stones";
cin>>t_stones;
int stones=t_stones/t_baskets; //whole stone
int pounds=t_stones%t_baskets; //remainder in pounds
cout<<t_stones<<" pounds are"<<stones<<" stone "<<pounds<<" pounds";
}
重点::求模运算符只用于整数,不能用于浮点

本文探讨了求模运算符%的使用,强调其仅适用于整数运算,不适用于浮点数。通过一个示例程序,展示了如何利用求模运算符进行单位换算,将重量从英石转换为磅,同时分离出整数部分和余数。
550

被折叠的 条评论
为什么被折叠?



