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 |
Re:原来递归不行。。。。In Reply To:原来递归不行。。。。 Posted by:vince4053040 at 2010-01-02 10:49:39 > #include<iostream> > using namespace std; > int roots(int m) > { > int i,s=0; > if(m == 0) return 0; > else if(m < 10) return m; > else { > for(i=0;m>=1;i++){ > s=s+m%10; > m=m/10; > } > return roots(s); > } > } > > int main() > { > int a; > while(cin>>a) > { > if(a==0) > break; > else > cout<<roots(a)<<endl; > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator