Friday, March 7, 2014

UVa Solution 11332 : Summing Digits

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    long long  num, remainder;
    while(scanf("%lld", &num))
    {
        if(num==0)
        {
            break;
        }
        while(num>9)
        {
            remainder = (num%10);
            num = (num/10);
            num = num+remainder;
        }
        printf("%lld\n", num);
    }
    return 0;
}

No comments:

Post a Comment

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...