相反数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41275621/article/details/79334461
为了得到一个数的"相反数",我们将这个数的数字顺序颠倒,然后再加上原先的数得到"相反数"。例如,为了得到1325的"相反数",首先我们将该数的数字顺序颠倒,我们得到5231,之后再加上原先的数,我们得到5231+1325=6556.如果颠倒之后的数字有前缀零,前缀零将会被忽略。例如n = 100, 颠倒之后是1. 
输入描述:
输入包括一个整数n,(1 ≤ n ≤ 10^5)


输出描述:
输出一个整数,表示n的相反数

输入例子1:
1325

输出例子1:

6556

#include <stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int x = n;//将n的值赋给x 
	int dight,sum;
	int ret=0;
	while(n>0)
	{
		dight = n%10;
		ret = ret*10+dight;
		n/=10;
	}
	sum=ret + x; 
	printf("%d",sum);
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41275621/article/details/79334461