Created
March 19, 2015 13:58
-
-
Save henrybear327/610ce15aea3806d6d406 to your computer and use it in GitHub Desktop.
uva 10035.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* | |
carry = add1%10 + add2%10 + carry; | |
carry /= 10; | |
add1 /= 10; | |
add2 /= 10; | |
if( carry ) | |
count++; | |
*/ | |
int main() | |
{ | |
long long int num1, num2; | |
while(scanf("%lld %lld", &num1, &num2) != EOF && !(num1 == 0 && num2 == 0)) { | |
int carry = 0, count = 0; | |
while(num1 || num2) { | |
int sum = num1 % 10 + num2 % 10 + carry; | |
carry = sum > 9 ? 1 : 0; | |
if(carry) | |
count++; | |
num1 /= 10; | |
num2 /= 10; | |
} | |
if(count == 0) | |
printf("No carry operation.\n"); | |
else if(count == 1) | |
printf("1 carry operation.\n"); | |
else | |
printf("%d carry operations.\n", count); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment