编程实现 有符号乘法溢出判断

//有符号乘法溢出判断 
#include<iostream>
using namespace std;
int tmult_ok(int x, int y )
{
    int pro = x*y;
    return !x || pro/x == y;
}
int main()
{
	unsigned int x,y,pro;
	cin>>x>>y;
	if (tmult_ok(x,y))
		cout<<"不溢出";
	else 
		cout<<"溢出";
	return 0; 
 } 

在这里插入图片描述

发布了164 篇原创文章 · 获赞 440 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_45884316/article/details/105141633
今日推荐