zoukankan      html  css  js  c++  java
  • 两个大数相乘

    # include<stdio.h> # include<string.h>
    # include
    <malloc.h>

    void multiply(char* a,char* b,char* c)
    {
       
    int i,j,ca,cb,* s;
        ca
    =strlen(a);
        cb
    =strlen(b);
        s
    =(int*)malloc(sizeof(int)*(ca+cb));
       
    for (i=0;i<ca+cb;i++)
            s[i]
    =0;
       
    for (i=0;i<ca;i++)
           
    for (j=0;j<cb;j++)
                s[i
    +j+1]+=(a[i]-'0')*(b[j]-'0');
       
    for (i=ca+cb-1;i>=0;i--)
           
    if (s[i]>=10)
            {
                s[i
    -1]+=s[i]/10;
                s[i]
    %=10;
            }
        i
    =0;
       
    while (s[i]==0)
            i
    ++;
          
    for (j=0;i<ca+cb;i++,j++)
               c[j]
    =s[i]+'0';
        c[j]
    ='\0';
        free(s);
    }

  • 相关阅读:
    画板
    多线程
    Runtime
    今日头条UI搭建
    支付宝UI界面搭建
    控制器的创建
    UIWindow简单介绍
    UIApplication
    UIPickerView的使用
    代理、通知、KVO
  • 原文地址:https://www.cnblogs.com/buffer/p/1585074.html
Copyright © 2011-2022 走看看