佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1339|回复: 10

新手问一下c++的问题.......

[复制链接]
发表于 8-12-2005 07:19 PM | 显示全部楼层 |阅读模式
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

评分

参与人数 1积分 -10 收起 理由
白日梦 -10 违反版规

查看全部评分

回复

使用道具 举报


ADVERTISEMENT

无奈 该用户已被删除
发表于 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 | 显示全部楼层
我只可以說一句。。。。你真的夠菜!!!!!功課不去做,貼士都給完了,還在叫。。。。。
回复

使用道具 举报

Follow Us
无奈 该用户已被删除
发表于 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积分。
回复

使用道具 举报


ADVERTISEMENT

jeefatt 该用户已被删除
发表于 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
....
....
....
....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 4-3-2025 04:36 PM , Processed in 0.536928 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表