搜索
查看: 2738|回复: 13
打印 上一主题 下一主题

321*(123456+54321)

[复制链接]
跳转到指定楼层
楼主
发表于 2013-4-18 16:08:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
321*(123456+54321)怎样编程

最佳答案

查看完整内容

#include #include int main() { int a,b,c,t; a=321; b=123456; c=54321; t=a*(b+c); printf("%d*(%d+%d)=%d\n",a,b,c,t); system("pause"); return 0;
沙发
发表于 2013-4-18 16:08:17 | 只看该作者
#include <stdio.h>
#include <stdlib.h>
int main()
{
        int a,b,c,t;
    a=321;
    b=123456;
    c=54321;
    t=a*(b+c);
    printf("%d*(%d+%d)=%d\n",a,b,c,t);
    system("pause");
        return 0;
板凳
发表于 2013-4-18 18:53:10 | 只看该作者
printf("%d\n", 321*(123456+54321));
地板
发表于 2013-4-19 13:54:41 | 只看该作者
#include <stdio.h>
int calculate(int,int,int,int);
int myPow(int ,int);
int main()
{
        int res;
        res=calculate(1,3,0,calculate(6,1,0,1)+calculate(1,5,0,1));
    printf("%d--%d\n",res);
        sleep(5000);
        return 0;
}
int calculate(int a,int b,int i,int n)
{
        int res;
        if(a>b)
    {
                res=a*myPow(10,i)*n;
                res+=calculate(a-1,b,i+1,n);
        return res;
    }
    else if(a<b)
    {
                res=a*myPow(10,i)*n;
                res+=calculate(a+1,b,i+1,n);
        return res;
    }
    else return a*myPow(10,i)*n;
}
int myPow(int x,int y)
{       
    if(y==0)return 1;
    if(y<0)return 0;
        int i,tempx=x,tempy=y;
        while(tempy>1)
    {
                tempx*=x;
        tempy--;
    }
    return tempx;
}
是要这样吗
5#
发表于 2013-4-21 18:57:41 来自手机 | 只看该作者
有这么麻烦吗?
6#
发表于 2013-4-21 21:36:06 | 只看该作者
我看前面的都没有采纳,就给他个复杂的,说不定口味重点儿
7#
发表于 2013-4-25 00:11:42 | 只看该作者
#include <stdio.h>
#include <stdlib.h>
int main()
{
        int a,b,c,d;
    a=321;
    b=123456;
    c=54321;
    d=a*(b+c);
    printf("%d",d);
        system("pause");
        return 0;
}
8#
发表于 2013-4-25 00:12:47 | 只看该作者
我也是新手,刚学完这一节。。。
9#
发表于 2013-4-25 15:47:06 | 只看该作者
int a,b,c,d;
a=321;
b=123456;
c=54321;
d=a*(b+c);
printf("%d",d);
10#
发表于 2013-4-26 23:25:40 | 只看该作者
那些简单的明显不靠谱。  int   定义 明显好像 溢出了。  应该long  int  定义   或者 也可以直接输出吧
11#
发表于 2013-4-27 01:27:30 | 只看该作者
hehui0314 发表于 2013-4-26 23:25
那些简单的明显不靠谱。  int   定义 明显好像 溢出了。  应该long  int  定义   或者 也可以直接输出吧
...

现在一般的C环境里还真不会溢出……
12#
发表于 2013-5-1 10:17:49 | 只看该作者
把int换成long int
因为123456这个数太大
13#
发表于 2013-5-1 10:36:17 | 只看该作者
狸小如 发表于 2013-5-1 10:17
把int换成long int
因为123456这个数太大

不要想当然
现在一般环境的int是32位的
这个问题里不会溢出
14#
发表于 2013-5-1 11:44:13 | 只看该作者
可是如果用int的话、、、反正我是这样做的,也许还有更好的方法吧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表