C++求模(取余)运算符与除法

求模运算符%是取余数的意思

重点::求模运算符只用于整数,不能用于浮点

计算有英石与磅数

#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";		
}

重点::求模运算符只用于整数,不能用于浮点

原创文章 7 获赞 10 访问量 269

猜你喜欢

转载自blog.csdn.net/lpblog/article/details/105876767