C语言输入一个任意数求各位数的和

                            C语言输入一个任意数求各位数的和

int main(void)
{
	int x, r, s = 0;
	scanf("%d", &x);
	while (x>0)
	{
		r = x % 10;
		s = s + r;
		x = x / 10;
	}
	printf("%d", s);
	
	getchar();
	system("pause");
	return 0;
	
}

猜你喜欢

转载自blog.csdn.net/weibo1230123/article/details/81359363