| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 325 人关注过本帖
标题:高手指导我这个程序出了什么问题
只看楼主 加入收藏
虚伪飞飞
Rank: 2
等 级:论坛游民
帖 子:11
专家分:14
注 册:2012-11-25
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:3 
高手指导我这个程序出了什么问题
题目是求整数m,n(0<m,n<10的50次方)的和(sum),积(product)?
我的代码是(有点长):

#include <stdio.h>

int main()
{
    char a[101];
    int b[50],c[50],sum[51],pro_1[101],i,k,l,d,e,f,su,pr,g,h,n;
    int state = 0;
    while (gets(a) != EOF)
    {
    for (i = 0;a[i] != '\0';i++)
    {
        if (a[i] == ' ')
            k = i;
    }
    l = i - 1 - k;
    e = 49;
    for (d = k - 1;d >= 0;d = d - 1)
    {
        b[e] = a[d] - 48;
        e = e - 1;
    }
    for (f = 0;f <= (49 - k);f++)
    {
        b[f] = 0;
    }
    e = 49;
    for (d = i - 1;d > k;d = d - 1)
    {
        c[e] = a[d] - 48;
        e = e - 1;
    }
    for (f = 0;f <= (49 - l);f++)
    {
        c[f] = 0;
    }
    e = 50;
    g = 0;
    for (d = 49;d >= 0;d = d - 1)
    {
        su = b[d] + c[d] + g;
        if (su < 10)
        {
                sum[e] = su;
                g = 0;
        }
        if (su >= 10)
        {
                sum[e] = su % 10;
                g = 1;
        }               
        if (d == 0)
        {
              if (su < 10)
              {
                      sum[0] = 0;
              }
              if (su >= 10)
              {
                      sum[0] = 1;
              }
        }                 
        e = e - 1;
    }
    state = 0;
    for (f = 0;f <= 50;f++)
    {
        if (state == 0 && sum[f] == 0);
        else if (state != 0 || sum[f] != 0)
        {
             state = 1;
             printf ("%d",sum[f]);
             if (f == 50)
                 printf ("\n");      
        }
    }
    g = 100;
    for (d = 49;d >= 0;d = d - 1)
    {
        pro_1[g] = c[d];
        g = g - 1;
    }
    for (d = 0;d <= 50;d++)
    {
        pro_1[d] = 0;
    }                        
    int pro_2[101] = {0};
    for (f = 0;f <= 49;f++)
    {
        g = 0;
        int pro_3[101] = {0};
        for (d = 0;d <= 100;d++)
        {
            pr = b[49 - f] * pro_1[100 - d] + g;
            if (pr < 10)
            {
                   pro_3[100 - d] = pr;
                   g = 0;
            }
            if (pr >= 10)
            {
                   pro_3[100 - d] = pr % 10;
                   g = pr / 10;
            }
            if (d == 100)
            {
                  if (pr <10)
                  {
                         pro_3[0] = 0;
                  }
                  if (pr >= 10)
                  {
                         pro_3[0] = pr/10;     
                  }
            }
        }
        h = 0;
        for (d = 100;d >= 1;d = d - 1)
        {
            su = pro_2[d] + pro_3[d] + h;
            if (su < 10)
            {
                   pro_2[d] = su;
                   h = 0;
            }
            if (su >= 10)
            {
                   pro_2[d] = su % 10;
                   h = 1;
            }
            if (d == 1)
            {
                  if (su < 10)
                  {
                         pro_2[0] = 0;
                  }
                  if (su >= 10)
                  {
                         pro_2[0] = 1;
                  }
            }              
        }
        for (d = 0;d <= 99;d++)
        {
            pro_1[d] = pro_1[d + 1];
            if (d == 99)
            {
                  pro_1[100] = 0;
            }
        }                  
    }
    state = 0;
    for (f = 0;f <= 100;f++)
    {
        if (state == 0 && pro_2[f] == 0);
        else if (state != 0 || pro_2[f] != 0)
        {
             state = 1;
             printf ("%d",pro_2[f]);
             if (f == 100)
                printf ("\n\n");  
        }
    }
    }
    return 0;
}
结果我输入ctrl+z结束不了,求高手指教?
搜索更多相关主题的帖子: product include 
2012-11-25 14:26
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:7 
那输入ctrl+c试试

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2012-11-25 15:55
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:7 
有的编译器EOF是ctrl+c

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-25 16:06
youngdavid
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:107
专家分:698
注 册:2012-9-24
收藏
得分:6 
在gcc编译器下ctrl+c 和ctrl+z都可以退出。
2012-11-29 22:01
快速回复:高手指导我这个程序出了什么问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027902 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved