怎么做数字的总和? [英] How to do sum of the digits?

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

问题描述

如何计算整数之和在0到1000之间?

示例整数是945:所有数字的总和是18.

这是我的任务,但我不知道从哪里开始,我需要你的帮助.. 。


我必须使用C ++语言吗...希望你们都能帮助我...


谢谢所有

How do you calculate the sum of the Integers is between 0 to 1000?
Examples integer is 945: the sum of all digits is 18.
This is my assignment but I don''t know where to start and I need your help...

I must use the C++ language do it... hope u all can help me...

Thanks all

推荐答案

这里有一个提示:


" modulo"

c ++%operator

... google that。
Here''s a hint:

"modulo"
in c++ the % operator
...google that.



这里有一个提示:


" modulo"

c ++%运算符

... google that。
Here''s a hint:

"modulo"
in c++ the % operator
...google that.



对不起我duno wat你的意思..如果可以做样本教我...我是真实的duno怎么做2编程..我从tis学习...感谢您的帖子

sorry i duno wat u meaning.. if can do the sample teach me... i reali duno how 2 do the programming.. i jus learn from tis years... thanks for your post


模数算术是算术的,包裹在一个给定的值,


,例如模数4


0 + 1 = 1

1 + 1 = 2

2 + 1 = 3

3 + 1 = 0


18模4是2.这是剩余时18除以4仅使用整数


18/4 = 4余数2

C / C ++%运算符包含这个,因为当1个整数除以另一个整数时它提供整数余数


18% 4 = 2;


DaLeach(我认为正确)建议您可以使用%运算符(和整数除法/)来执行计算。

整数算术


18%10 = 8;

18/10 = 1;


我们不会去为你准备一个程序,因为你不会学到任何东西,但如果你试图编写程序,我们会帮助你解决任何错误。


写点东西,确保它编译没有警告或询问是否有错误或警告你不明白。如果它没有工作发布你的代码我们会帮助。
Modulo arithmatic is arithmatic that wraps at a given value,

for instance in modulo 4

0 + 1 = 1
1 + 1 = 2
2 + 1 = 3
3 + 1 = 0

18 modulo 4 is 2. This is the remainder when 18 is divided by 4 using only whole numbers

18 / 4 = 4 remainder 2

The C/C++ % operator encompases this as it provides the integer remainder when 1 integer is divided by another

18 % 4 = 2;

DaLeach is (correctly in my opinion) suggesting that you can use the % operator (and interger divide /) to perform your calculation.

In integer arithmatic

18 % 10 = 8;
18 / 10 = 1;

We are not going to write a program for you as you will not learn anything but if you have an attempt at writing a program we will help you with any errors in it.

Write something, make sure it compiles without warnings or ask if there are errors or warnings you don''t understand. if it doesn''t work post your code and we''ll help.


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

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