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

Re:原来递归不行。。。。

Posted by huyoulai at 2010-09-24 18:56:42 on Problem 1519
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:
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