進位2

 avatar
user_3763047219
c_cpp
2 years ago
1.2 kB
3
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
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 (i != timen - 2) {
			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");
			}
		}
		else {
			if (count == 1) {
				printf("%d carry operation.", count);
			}
			else if (count > 1) {
				printf("%d carry operations.", count);
			}
			else {
				printf("No carry operation.");
			}
		}
		
	}
}