Skip to content

Instantly share code, notes, and snippets.

@somratcste
Created February 11, 2014 08:17
Show Gist options
  • Save somratcste/8931015 to your computer and use it in GitHub Desktop.
Save somratcste/8931015 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
unsigned long a,b,count,carry,m;
while(scanf("%ld%ld",&a,&b)==2 && a!=0 && b!= 0)
{
count=0,m=0;
while(a||b )
{
carry=a%10+b%10+m;
if(carry>9){
m=10-carry;
count++;
}
a=a/10;
b=b/10;
}
if(count==0)
cout<<"No carry operation."<<endl;
else if(count==1)
cout<<"1 carry operations."<<endl;
else
printf("%d carry operation.\n",count);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment