Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created March 19, 2015 13:58
Show Gist options
  • Save henrybear327/610ce15aea3806d6d406 to your computer and use it in GitHub Desktop.
Save henrybear327/610ce15aea3806d6d406 to your computer and use it in GitHub Desktop.
uva 10035.c
#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