蓝桥杯 整商问题 C++算法提高 HERODING的蓝桥杯之路

资源限制时间限制:1.0s 内存限制:256.0MB问题描述  提示用户输入被除数(dividend)和除数(divisor),若除数为0,则提示用户重新输入,直至除数非零为止。最后输出商。程序建议大家将被除数、除数和商都定义为整形。

输入被除数提示语句为:Please enter the dividend:

输入除数提示语句为:Please enter the divisor:

提示除数为0需要重新输入的语句为: Error: divisor can not be zero! Please enter a new divisor:

建议:大家直接复制上述语句,以免出现不必要的错误。输入格式  被除数 除数

注:若除数为零,则需要连续输入除数直至其非零为止。输出格式  提示性语句 商

注意每个提示性语句输出后需要换行,具体参考下面的样例输出。样例输入一个满足题目要求的输入范例。

例1:

10 2

例2:

20 0 0 4样例输出与上面的样例输入对应的输出。

例1:

Please enter the dividend:

Please enter the divisor:

5

例2:

Please enter the dividend:

Please enter the divisor:

Error: divisor can not be zero! Please enter a new divisor:

Error: divisor can not be zero! Please enter a new divisor:

5数据规模和约定  无

解题思路:
这道题目很简单,就是按照题设所给的要求进行答题即可,需要注意的室输入的文字的大小写问题,输出换行问题,以及遇到零的时候需要循环的问题。代码如下:

#include<bits/stdc++.h>

using namespace std;

int main(){
	int m, n;
	
	cin >> m;
	cout << "Please enter the dividend:" << endl;
	cout << "Please enter the divisor:" << endl;
	while(1){
		cin >> n;
		if (n != 0){
			break;
		}else{
			cout << "Error: divisor can not be zero! Please enter a new divisor:" << endl;	
		}
	}
	cout << m / n;
	return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HERODING77

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值