Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why wrong answer#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator