1017 A除以B(20分)

题目要求

本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数。你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立。

输入格式:

输入在一行中依次给出 A 和 B,中间以 1 空格分隔。
输出格式:

在一行中依次输出 Q 和 R,中间以 1 空格分隔。
输入样例:

123456789050987654321 7

输出样例:

17636684150141093474 3

答案:

#include<stdio.h>

int main()
{
	char a[1000];
	int b,i;
	scanf("%s %d",&a,&b);
	int temp,t,flag;
	temp=0;
	t=0;
	flag=0;
	if(a[1]==NULL&&a[i]-'0'<b)
	printf("0");
	for(i=0;a[i]!=NULL;i++)
	{
		t=(int)(a[i]-'0')+t*10;
		temp=t/b;
		t=t%b;
		if(flag==0&&temp==0);
		else
		printf("%d",temp);
	 flag++;
	}	
	printf(" %d",t);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/weixin_43393567/article/details/88776285