UVA-10035 Primary Arithmatic

#include <stdio.h>
int main()
{
    int a,b,i,j,r,r1,c,s,t;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        c=0;
        t=0;
        if(a==0 && b==0)
        {
            break;
        }
        while(1)
        {
            if(a==0 && b==0)
            {
                break;
            }
            r=a%10;
            r1=b%10;
            if(t==1)
            {
                s=r+r1+1;

            }
            else
            {
                s=r+r1;
            }

            if(s>9)
            {
                c++;
                t=1;
            }
            else
            {
                t=0;
            }
            a=a/10;
            b=b/10;
        }
        if(c==0)
        {
            printf("No carry operation.\n");
        }
        else if(c==1)
        {
             printf("%d carry operation.\n",c);
        }
        else
        {
         printf("%d carry operations.\n",c);
        }

    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment