zoukankan      html  css  js  c++  java
  • 大数加法

    /*************************************************************************
        > File Name: big_sum.c
        > Author: 傻李
        > Mail: hellojukay@gmail.com 
        > Created Time: 2014年11月15日 星期六 11时36分29秒
     ************************************************************************/
    
    #include<stdio.h>
    #include<string.h>
    #define MAX 1000
    int result[MAX];
    
    void add(char *str1,char *str2)
    {
     int a[MAX],b[MAX];
     memset(result,0,MAX * sizeof(int));
     memset(a,0,MAX * sizeof(int));
     memset(b,0,MAX * sizeof(int));
     int c;//进位表示
     int sum;
     int i,j;
     for(i = strlen(str1) - 1, j = 0; i >=0; --i,++j)
     {
     a[j] = str1[i] - '0';
     }
     for( i = strlen(str2) - 1, j = 0; i >=0; --i,++j)
     {
     b[j] = str2[i] - '0';
     }
     c = 0;
     for(i = 0 ; i < MAX; ++i)
     {
     sum = a[i] + b[i] + c;
     result[i] = sum % 10;
     c = sum / 10;
     }
    
    }
    
    int main()
    {
     int i;
     char a[MAX],b[MAX];
     memset(result,0,MAX);
     scanf("%s",a);
     getchar();
     scanf("%s",b);
     add(a,b);
     for(i = MAX -1; i >=0; --i)
     {
     if(result[i] !=0)
     {
     for(;i>=0; --i)
     printf("%d",result[i]);
     break;
     }
     }
     getchar();
     return 0;
    }
    =-=-=-=-=
    Powered by Blogilo
  • 相关阅读:
    厂商前缀
    文本阴影和边框阴影
    2D转换
    overflow属性
    margin属性
    CSS圆角边框
    浮动定位
    文档流定位
    position属性
    选择器二
  • 原文地址:https://www.cnblogs.com/shuimojun/p/4099466.html
Copyright © 2011-2022 走看看