進位(沒陣列)

 avatar
user_3763047219
c_cpp
2 years ago
656 B
1
Indexable
Never
int main()
{
	int n1=-1,n2=-1,newn1, newn2;
	int sum1 = 0;
	int count = 0, total = 0;
	int index = 0, timen = 0;
	
	while (n1!=0 && n2!=0) {
		scanf("%d%d", &n1, &n2);
		count = 0;
		newn1 = n1;
		newn2 = n2;
		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");
		}
	}
}