進位

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.0 kB
0
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>//header standard Input/ouput
#include<stdbool.h>
//#include<assert.h>
#include<math.h>

int main()
{
	int newn1,newn2;
	int sum1=0;
	int count=0,total=0;
	int n1arr[10000] = {},n2arr[10000]={};
	int index=0,timen=0;
	while (index>=0) {
		scanf("%d%d", &n1arr[index], &n2arr[index]);
		if (n1arr[index] == 0 && n2arr[index] == 0) {
			index = -1;
		}
		else {
			index = index + 1;
		}
		timen = timen + 1;
	}
	for (int i = 0;i < timen -1;i++) {
		count = 0;
		newn1 = n1arr[i];
		newn2 = n2arr[i];
		while (newn1 >= 1 && newn2 >= 1) {
			sum1 = sum1+ newn1 % 10 + newn2 % 10;
			if (sum1 >= 10) {
				count = count + 1;
				sum1 = 1;
			}
			else {
				sum1 = 0;
			}
			newn1 = newn1 / 10;
			newn2 = newn2 / 10;
		}
		if (count == 1) {
			printf("%d carry operation.\n",count);
		}
		else if (count > 1) {
			printf("%d carry operations.\n", count);
		}
		else {
			printf("No carry operation.\n");
		}
	}
}