Ad

Saturday, March 16, 2013

Uva 10035 - Primary Arithmetic, so easy than other programing problem

Problem ID - 10035,
Problem Name - Primary Arithmetic.

Problem Description is Here


#include<stdio.h>

main()
{
    unsigned long int num1, num2, temp1, temp2;
    int carry, r;


    while(scanf("%lu %lu", &num1, &num2)==2 && (num1!=0 || num2!=0))
    {
        carry = 0; r=0;
        while(num1!=0 || num2!=0)
        {
            temp1=num1%10;
            num1=num1/10;
            temp2=num2%10;
            num2=num2/10;

            if((temp1+temp2)+r >9)
            {
                carry++;
                r=1;
            }
            else
            {
                r=0;
            }
        }
        if(carry==0)
        {
            printf("No carry operation.\n");
        }
        else if(carry==1)
        {
            printf("1 carry operation.\n");
        }
        else
        {
            printf("%d carry operations.\n", carry);
        }
    }
return 0;
}

0 comments:

Post a Comment