the homework

Problem: write a float A/B=1/a1+1/a2+...
such as 5/6=1/2+1/3
7/8=1/2+1/4+1/8


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
using namespace std;
int main()
{     
	int c[100];
		
	int A;
	int B;
	cout<<"please input two numbers"<<endl;
	cin>>A;
	cin>>B;
     int k=0;
	 while(A>0)
	 {
		 int r=B%A;
		 int C=B-r;
		 c[k]=C/A;
		 c[k]=c[k]+1;
		 A=c[k]-B;
		 B=B*c[k];
		 k++;
}
	 for(int p=0;p<=k;p++)
		 cout<<c[p];
	 system("pause");
	 return 0;
}
my code is not right, and has some issues.but the algorithm is form a ACM book, which is right.
Topic archived. No new replies allowed.