查看: 1340|回复: 10
|
新手问一下c++的问题.......
[复制链接]
|
|
1. Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of 3456 as 3 4 5 6; output the individual digits of 8030 as 8 0 3 0; output the individual digits of 2345526 as 2 3 4 5 5 2 6; output the individual digits of 4000 as 4 0 0 0; and output the individual digits of –2345 as 2 3 4 5.
请问要如何叫人叫打个number,如2453,然后output 出来是2 4 5 3 呢。。。?
我找不到想不到有类似的command |
评分
-
查看全部评分
|
|
|
|
|
|
|
发表于 8-12-2005 10:54 PM
|
显示全部楼层
有很多不同的方法...
可以朝把int换成string来想...或用 %.... |
|
|
|
|
|
|
|

楼主 |
发表于 9-12-2005 02:54 PM
|
显示全部楼层
是不是除1000.....100....然后放%? 如果人家打四位数我只会拿最前面的,第二个第三我不会拿... |
|
|
|
|
|
|
|
发表于 9-12-2005 07:18 PM
|
显示全部楼层
嘿嘿嘿,我連 compile 都沒試過了。但答案應該不會差太遠了。
int IntDigits(int Value)
{
if (Value > 9)
{
int Result = IntDigits(Value / 10);
cout << " " << Value % 10;
return (Value % 10) + Result;
}
cout << " " << Value << endl;
return Value;
} |
|
|
|
|
|
|
|

楼主 |
发表于 9-12-2005 07:47 PM
|
显示全部楼层
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int Value;
int main()
{
int IntDigits(int Value);
{
cin>>Value;
if (Value > 9)
{
int Result = IntDigits(Value / 10);
cout << " " << Value % 10;
return (Value % 10) + Result;
}
cout << " " << Value << endl;
return Value;
}
}
不可以。。。 出现error
[Linker error] undefined reference to `IntDigits(int)' |
|
|
|
|
|
|
|
发表于 9-12-2005 09:47 PM
|
显示全部楼层
我只可以說一句。。。。你真的夠菜!!!!!功課不去做,貼士都給完了,還在叫。。。。。 |
|
|
|
|
|
|
|
发表于 9-12-2005 11:15 PM
|
显示全部楼层
原帖由 馬拉棧 于 9-12-2005 07:18 PM 发表
嘿嘿嘿,我連 compile 都沒試過了。但答案應該不會差太遠了。
int IntDigits(int Value)
{
if (Value > 9)
{
int Result = IntDigits(Value / 10);
cout << & ...
呵呵,好像不能直接给code  |
|
|
|
|
|
|
|
发表于 10-12-2005 09:11 AM
|
显示全部楼层
谢谢楼上提醒。
楼主没尝试自己作业下拿了答案,谢谢惠顾-10积分。 |
|
|
|
|
|
|
|
发表于 14-1-2006 01:39 PM
|
显示全部楼层
我想将我写好的exe file attach 去其他file 如doc or jpeg ... 请问要怎样弄??? please reply... |
|
|
|
|
|
|
|
发表于 15-1-2006 11:51 AM
|
显示全部楼层
原帖由 akito 于 9-12-2005 07:47 PM 发表
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int Value;
int main()
{
int IntDigits(int Value);
{
cin>>Value;
if (Value > ...
wah lau eh,大佬,你做么直接把function放进main里面。。。 |
|
|
|
|
|
|
|
发表于 15-1-2006 12:35 PM
|
显示全部楼层
比较简单的方法就是
/1000 再减掉答案*1000咯
例如
答案=DIGIT/1000
cout>>答案>>end1
DIGIT-=*1000
....
....
....
.... |
|
|
|
|
|
|
| |
本周最热论坛帖子
|