为什么不输出负数?如何去掉末尾反转后的0?
查看原帖
为什么不输出负数?如何去掉末尾反转后的0?
753239
Li_Junlin楼主2022/8/22 17:21
#include<bits/stdc++.h>
using namespace std;
int main()
{

	int x,y;
	cin>>x;
	if(x>0)
	{
	while(x>0)
	{
		y=x%10;
		cout<<y;
		x/=10;
	}
	}
	**else if(x<0)
	{
		cout<<"-"; 
	while(-x<0)
	{
		y=-x%10;
		cout<<y;
		x/=10;
	}
	}**
    else
    cout<<'0';
	return 0;
}
2022/8/22 17:21
加载中...