太阳的数字中的数字 [英] Sun of digits in a number

查看:125
本文介绍了太阳的数字中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想知道怎么做:

基本上当我输入一个数字,比如123时,它应该显示6

(1 + 2 +3),对于666将是18.我有点卡在这里...


我知道它会涉及到一个循环,可以做到这个条件:


nd1 = num / 100%10;

nd2 = num / 10%10;

nd3 = num%10;等


还有一些如何加起来。谁能帮我?谢谢。

Hello, I would like to know how to do this:
Basically when I input a number, such as 123, it should display 6
(1+2+3), and for 666 would be 18. I''m a bit stuck here...

I know it would involve a while loop along that can do this condition:

nd1=num/100%10;
nd2=num/10%10;
nd3=num%10;, etc

And some how add it up. Can anyone help me? Thanks.

推荐答案

sn *********** @ gmail.com 写道:
您好,我想知道如何做到这一点:
基本上当我输入一个数字,比如123,它应该显示6
(1 + 2 + 3),而666则是18.我有点卡在这里...

我知道它会涉及到一个循环,可以做到这个条件:

nd1 = num / 100%10;
nd2 = num / 10%10;
nd3 = num %10;等等

还有一些如何添加它。谁能帮我?谢谢。
Hello, I would like to know how to do this:
Basically when I input a number, such as 123, it should display 6
(1+2+3), and for 666 would be 18. I''m a bit stuck here...

I know it would involve a while loop along that can do this condition:

nd1=num/100%10;
nd2=num/10%10;
nd3=num%10;, etc

And some how add it up. Can anyone help me? Thanks.




好​​吧,如果你只做一次:


nd = num%10;

nn = num / 10;


你得到了什么?如果您采取其中一个结果并继续使用它(而不是''num'')进行相同的操作怎么办?你会多少次b
来做这件事?您需要添加哪些数字以及在哪里?


V



Well, if you do it only once:

nd = num % 10;
nn = num / 10;

what do you get? What if you take one of those results and keep doing
the same operation with it (instead of ''num'')? How many times will you
get to do it? What numbers will you need to add and where?

V


sn *********** @ gmail.com 写道:
您好,我想知道怎么做:
基本上当我输入一个数字,比如123,它应该显示6
(1 + 2 + 3),而666则是18.我有点卡在这里...

我知道它会涉及到一个循环,可以做到这种情况:

nd1 = num / 100%10;
nd2 = num / 10%10;
nd3 = num%10;等等

还有一些如何添加它。谁能帮我?谢谢。
Hello, I would like to know how to do this:
Basically when I input a number, such as 123, it should display 6
(1+2+3), and for 666 would be 18. I''m a bit stuck here...

I know it would involve a while loop along that can do this condition:

nd1=num/100%10;
nd2=num/10%10;
nd3=num%10;, etc

And some how add it up. Can anyone help me? Thanks.



反过来说:取模数得到一个数字,然后除了10,如果不是零则再做一次。


不止于此,我不会提供。你的老师要你做你自己的家庭作业。


Do it the other way around: take the modulo to get a digit,
then divide by ten, if not zero do it all again.

More than that, I will not offer. Your teacher wants you to do
your own homework.


谁说这是家庭作业?我在业余时间这样做,因为我想要学习C ++。我已经说过我记得的了,但只是

忘了怎么做。我知道我可以使用while循环,但我不是

确定如何在此之后设置它。请不要假设。

Who said it was homework? I''m doing this on my spare time because I
want to learn C++. I''ve already said what I remember, but just
forgetting how to do it. I know I can use a while loop, but I''m not
sure how to set it up after that. Please don''t assume things.


这篇关于太阳的数字中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆