码迷,mamicode.com
首页 > 编程语言 > 详细

a*b高精度数组算法

时间:2019-02-23 15:57:26      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:需要   har   精度   printf   turn   要求   nbsp   get   a*   

#include<stdio.h>
#include<string.h>
int main()
{
    int a[40]={0},b[40]={0},c[100]={0},len1=0,len2=0;
    char str1[40],str2[40];
    gets(str1);len1=strlen(str1);
    gets(str2);len2=strlen(str2);
    int i,j;
    for(i=0;i<len1;i++)
    {
        a[i]=str1[len1-i-1]-0;//由于len1-i=3(first),so需要-1,使其符合要求。
    }
    for(j=0;j<len2;j++)
    {
        b[j]=str2[len2-j-1]-0;
    }
    for(i=0;i<len1;i++)
    {
        for(j=0;j<len2;j++)
    {
        c[i+j]+=a[i]*b[j];
        if(c[i+j]>=10)
        {
             c[i+j+1]+=c[i+j]/10;
             c[i+j]%=10;
        }
    }
    }
    for(i=len1+len2;i>0;i--)
    {
        if(c[i]!=0)
            break;
    }
    do
    {
        printf("%d",c[i]);
    }
    while(i--);
    printf("\n");
    return 0;
}

 

a*b高精度数组算法

标签:需要   har   精度   printf   turn   要求   nbsp   get   a*   

原文地址:https://www.cnblogs.com/ZZ34/p/10422894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!