标题:斐波那契数列(大数相加)
只看楼主
skyuser213
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:37
专家分:117
注 册:2010-5-9
 问题点数:0 回复次数:1 
斐波那契数列(大数相加)
不要砸我鸡蛋啊
程序代码:
#include <stdio.h>

int main(int argc, char* argv[])
{
  int nBinary = 0;
  int nDigital = 1;
  int nTemp = 0;
  int nMark = 0;
  int nNumber = 0;
  int nNumberArrayOne[10000] = {0};
  int nNumberArrayTwo[10000] = {0};

  nNumberArrayOne[0] = 0;
  nNumberArrayTwo[0] = 1;

  printf("要查询第几项:");
  scanf("%d", &nNumber);

  for (int i = 1; i < nNumber; i++)
  {
    if (nMark == 0)
    {
      for (int j = 0; j < nDigital; j++)
      {
        nTemp = nNumberArrayOne[j] + nNumberArrayTwo[j] + nBinary;
        nNumberArrayOne[j] = nTemp % 10;
        nBinary = nTemp / 10;
      }
      while(nBinary)
      {
        nDigital++;
        nNumberArrayOne[nDigital - 1] = nBinary % 10;
        nBinary = nBinary / 10; 
      }
      nMark = 1;
    }
    else
    {
      for (int j = 0; j < nDigital; j++)
      {
        nTemp = nNumberArrayOne[j] + nNumberArrayTwo[j] + nBinary;
        nNumberArrayTwo[j] = nTemp % 10;
        nBinary = nTemp / 10;
      }
      while(nBinary)
      {
        nDigital++;
        nNumberArrayTwo[nDigital - 1] = nBinary % 10;
        nBinary = nBinary / 10; 
      }
      nMark = 0;
    }
  }

 
  if (nMark == 0)
  {
    for (int k = nDigital - 1; k >= 0; k--)
    {
      printf("%d", nNumberArrayTwo[k]);
    }
    puts("");
  }
  else
  {
    for (int k = nDigital - 1; k >= 0; k--)
    {
      printf("%d", nNumberArrayOne[k]);
    }
    puts("");
  }

 
  return 0;
}
搜索更多相关主题的帖子: 大数 相加 
2010-05-28 22:30
LSYHEFENG
Rank: 2
等 级:论坛游民
帖 子:112
专家分:71
注 册:2010-7-17
得分:0 
能不能加点注释啊
2010-08-01 15:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-308560-1-1.html




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

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