加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

C语言:大数相乘.

发布时间:2020-12-14 03:29:02 所属栏目:大数据 来源:网络整理
导读:#includestdio.h#includestring.h#define N 200void mul(char a[],int n,char b[],int m){int s[N] = {0},i=N-1,p=0;int l,j;for( ; n=0; n--){for(j=i,l=m; l=0; j--,l--){s[j] = s[j] + (a[n]-'0')*(b[l]-'0')+p;p = s[j]/10;s[j] = s[j]%10;} while(p){ s
#include<stdio.h>
#include<string.h>
#define N 200
void mul(char a[],int n,char b[],int m)
{
	int s[N] = {0},i=N-1,p=0;
	int l,j;
	for( ; n>=0; n--)
	{
		for(j=i,l=m; l>=0; j--,l--)
		{
			s[j] = s[j] + (a[n]-'0')*(b[l]-'0')+p;
			p = s[j]/10;
			s[j] = s[j]%10;
		}
	   	while(p)
		{
	    	s[j--] = p%10;
		    p = p/10;
		}
		i--;
	}
	for(i=j+1; i<N; i++)
		printf("%d",s[i]);
	printf("n");
}

int main()
{
	char a[20],b[20];
	int n,m;
	printf("nPlease input the first  number: ");
	gets(a);
	n = strlen(a)-1;
	printf("nPlease input the second number: ");
	gets(b);
	m = strlen(b)-1;
	printf("nThe two  numbers  multibly is: ");
	mul(a,n,b,m);
	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读