大整数乘法和除法

#include "stdio.h"

char ch[500+4];

int ch2[500+4];
//大整数的除法
int div (int num) {
	int i;
	int t = 0;
	int index = 0;
	int flag = 0;
	int size = strlen (ch);
	for (i = 0;i < size;i++) {
		t = t * 10  + (ch[i] - '0');
		if (t < num) {
			if (flag) {
				ch2[index++] = 0;	
			}
			continue;
		}
		flag = 1;
		ch2[index++] = t / num;
		t = t % num;
	}
	return t;
	//t是余数
}
int main () {
	int i;
	int n;
	int t;
	scanf ("%d",&n);
	
	for (i = 0;i < n;i++) {
		scanf ("%s",ch);
		t = div (3);
		if (t) {
			printf ("No");	
		}else {
			printf ("Yes");
		}
		t = div (11);
		if (t) {
			printf (" No");	
		}else {
			printf (" Yes");
		}
		printf ("\n");
	}	
	return 0;
}

#include "stdio.h"


#define MAX 3000+5



int result[MAX];

int main () {
	int n;
	int i;
	int j;
	int carry = 0;
	int t;
	scanf ("%d",&n);
	memset (result,0,sizeof(result));
	result[0] = 1;
	for (i = 2;i <= n;i++) {
		//乘上i
		for (j = 0;j < MAX;j++ ) {
			t = i * result[j] + carry;
			result[j] = t % 10;
			carry = t / 10;	
		}
	}
	j = MAX - 1;
	while (!result[j]) {
		j--;
	}
	for (i = j;i >=0;i--) {
		printf ("%d",result[i]);
	}
	printf ("\n");
	return 0;
}

    原文作者:大整数乘法问题
    原文地址: https://blog.csdn.net/xiao_niu_1/article/details/10420027
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞