41/468 = 0.08(760683)
6 = number of digits in repeating cycle
1169/725 = 1.61(2413793103448275862068965517)
28 = number of digits in repeating cycle
2962/465 = 6.3(698924731182795)
15 = number of digits in repeating cycle
2705/1146 = 2.3(60383944153577661431064572425828970331588132635253...)
95 = number of digits in repeating cycle
2281/1828 = 1.24(78118161925601750547045951859956236323851203501094...)
152 = number of digits in repeating cycle
961/492 = 1.95(32520)
5 = number of digits in repeating cycle
1/397 = 0.(00251889168765743073047858942065491183879093198992...)
99 = number of digits in repeating cycle
why you breaking it down in three lines? i got PE. my output was like
[code]
2099/1 = 2099.(0)
1 = number of digits in repeating cycle
20/20 = 1.(0)
1 = number of digits in repeating cycle
10/9 = 1.(1)
1 = number of digits in repeating cycle
1001/998 = 1.0(0300601202404809619238476953907815631262525050100...)
498 = number of digits in repeating cycle
890/901 = 0.(98779134295227524972253052164261931187569367369589...)
208 = number of digits in repeating cycle
2999/928 = 3.23168(1034482758620689655172413793)
28 = number of digits in repeating cycle
Hi, guys... Could somebody help me find what's wrong with my 202 code..
The system replay I have a Runtime error. But I can't find what's wrong.
I also increase the arraysize to 2000 but it still doesn't work.
BTW, my coding is not good. I'll appreciate if anyone can give any advice to revise my code.
//ACM 202 Repeating decimals
#include <iostream>
using namespace std;
int main(void){
int n1, n2;
int decimals[2000];
int remainder[2000];
int coef = 0;
int idx = 0;
bool found = false;
int length = 0; //Count the number of repeating cycle
int startIdx = 0;
while (cin>> n1>> n2){
idx = 0;
startIdx = 0;
length = 0;
found = false;
cout << n1 << "/" << n2 << " = " << static_cast<int>(n1/n2) << "." << flush;
while(!found){
if (n1/n2)
n1 = n1 - static_cast<int>(n1/n2) * n2;
n1 *= 10;
remainder[idx] = n1 % n2;
decimals[idx] = n1/n2;
// Find the repeat remainder
for (int i = 0; i != idx; i++) {
if (remainder == remainder[idx]){
found = true;
if (remainder[idx] == 0) // Means A|B
{
length = 1;
startIdx = idx;
found = true;
break;
}
else{
length = idx - i;
startIdx = i;
}
}
}
if (!found)
idx++;
}
if (length <= 1) // Means A|B
{
for (int k = 0; k != idx; k++)
cout << decimals[k];
cout << "(" << decimals[idx] << ")" << endl;
}
else { // Means A can not divided by B.. It has remainder
for (int k = 0; k != idx; k++) {
if (k == 50) {
cout << "...";
break;
}
if (k == startIdx)
cout << "(";
cout << decimals[k] ;
}
cout << ")" << endl;
}
cout << " " << length << " = number of digits in repeating cycles" << endl;
cout << endl;
}
//system("pause");
return 0;
}
I have tried all the test cases can be found in the site?and all i'o are correct?and I do not know what's wrong with my cod.
Help me,plz;
Or if you give me some critic I/OI will also appreciate if you give me some critic I/O
Here is my code