Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why wrong answer

Posted by gothree at 2006-11-13 20:39:38 on Problem 1519
#include <stdio.h>
int main()
{
    char input[1000],i=0;
    while(scanf("%s",input)==1) //input the digits
    {
        long digit=0;
        for(i=0;input[i]!='\0';i++)   //calculate the sum of the digits 
            digit+=input[i]-48;
        while(digit>=10)             //work out the answer
        {
            long temp=0;
            while(digit)
            {
                temp+=digit%10;
                digit/=10;
            }
            digit=temp;
        }
        if(digit==0)                 //if the input is 0,then the value of digit is 0
            return 0;
        printf("%ld\n",digit);
    }
}
just help me

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator