大整数相乘

输入一个长整型数s和一个整数c, 求s×c的精确值。

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

int main()
{
    int b,i;
    long int s[50]={0};
    char a[50];
    scanf("%s%d",a,&b);
    for(int j=strlen(a)-1;j>=0;j--)//b从a的最低位依次乘到最高位
    {
        i = strlen(a)-j-1;//注意下标的变化
        s[i] += (a[j] - '0')*b;
        s[i+1] = s[i]/10;//先取余会导致s[i]值发生变化
        s[i] = s[i]%10;
    }
    for(int t=i+(s[i+1]!=0);t>=0;t--)
        printf("%d",s[t]);
    printf("\n");
    return 0;
}

 

posted @ 2016-07-12 12:22  我在这儿  阅读(203)  评论(0编辑  收藏  举报