Printing 0.346346346 as 0.(346)
-
Hi All, Can anyone please give me an idea to write a program(any language) to print 0.123123123 as 0.(123) and 0.346346346 as 0.(346) if both the numerator and denominator are given?
Regards, Arun Kumar.A
-
Hi All, Can anyone please give me an idea to write a program(any language) to print 0.123123123 as 0.(123) and 0.346346346 as 0.(346) if both the numerator and denominator are given?
Regards, Arun Kumar.A
Here's some C++ code:
double value = 0.123123123;
printf("%0.3lf", value);Her it is in C#:
double nVal = 0.346789123;
string sVal = string.Format("{0:#.000}", nVal);Here it is in VB:
START:
print("Not a real programming language")
goto START"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Here's some C++ code:
double value = 0.123123123;
printf("%0.3lf", value);Her it is in C#:
double nVal = 0.346789123;
string sVal = string.Format("{0:#.000}", nVal);Here it is in VB:
START:
print("Not a real programming language")
goto START"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001So you didn't understand the question properly. Have you noticed that repeating patterns are enclosed within parenthesis. For example: 0.565656 => 0.(56) 0.111111 => 0.(1) 0.123412341234=> 0.(1234)
Regards, Arun Kumar.A
-
So you didn't understand the question properly. Have you noticed that repeating patterns are enclosed within parenthesis. For example: 0.565656 => 0.(56) 0.111111 => 0.(1) 0.123412341234=> 0.(1234)
Regards, Arun Kumar.A
If you pay me $500, I'll write you a function to do that in C++. If you pay me $1000, I'll do it in C#. If you pay me $10,000, I'll do it in VB. I don't work that hard for free.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
If you pay me $500, I'll write you a function to do that in C++. If you pay me $1000, I'll do it in C#. If you pay me $10,000, I'll do it in VB. I don't work that hard for free.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
$10,000, I'll do it in VB.
Are you sure? I mean its VB and I know your views on the subject :laugh:
-
If you pay me $500, I'll write you a function to do that in C++. If you pay me $1000, I'll do it in C#. If you pay me $10,000, I'll do it in VB. I don't work that hard for free.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001I didn't ask you to write the program.. Please read the original post.. I have asked just the idea.. Not the program..
Regards, Arun Kumar.A
-
Hi All, Can anyone please give me an idea to write a program(any language) to print 0.123123123 as 0.(123) and 0.346346346 as 0.(346) if both the numerator and denominator are given?
Regards, Arun Kumar.A
Hi Arun, in your notation 0.(Z) with Z an arbitrary sequence of digits has the value Z/N where N consists of n times the digit 9, n being the length of sequence Z. So in order to have the equality X/Y = "0.(Z)" you must solve X/Y=Z/N or N=Z*Y/X for Z and n The easiest way to do this is using a loop where n grows from 1 to infinity, then try to evenly divide N (n digits 9) by Y The first solution, if any, is the one you want. Examples: X=1, Y=3 try n=1 N=9 solved ! found "0.(3)" X=1, Y=37 n=1? 9/37 no way n=2? 99/37 nope n=3? 999/37=27 found "0.(027)" The next interesting question is how do you know you tried a sufficiently long sequence of nines ? Clearly if X=1, Y=2 you will never find a solution ! :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Hi Arun, in your notation 0.(Z) with Z an arbitrary sequence of digits has the value Z/N where N consists of n times the digit 9, n being the length of sequence Z. So in order to have the equality X/Y = "0.(Z)" you must solve X/Y=Z/N or N=Z*Y/X for Z and n The easiest way to do this is using a loop where n grows from 1 to infinity, then try to evenly divide N (n digits 9) by Y The first solution, if any, is the one you want. Examples: X=1, Y=3 try n=1 N=9 solved ! found "0.(3)" X=1, Y=37 n=1? 9/37 no way n=2? 99/37 nope n=3? 999/37=27 found "0.(027)" The next interesting question is how do you know you tried a sufficiently long sequence of nines ? Clearly if X=1, Y=2 you will never find a solution ! :)
Luc Pattyn [My Articles] [Forum Guidelines]
Thank you very much. You have been most helpful.:):):)
Regards, Arun Kumar.A
-
Thank you very much. You have been most helpful.:):):)
Regards, Arun Kumar.A
You're welcome. I would suggest you pay extra attention to my final remark, since an algorithm that potentially takes forever is not really an algorithm (an algorithm is supposed to provide a solution in a finite time and at a reasonable cost). Some more math should lead you to a maximum for n, depending on X and Y. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
You're welcome. I would suggest you pay extra attention to my final remark, since an algorithm that potentially takes forever is not really an algorithm (an algorithm is supposed to provide a solution in a finite time and at a reasonable cost). Some more math should lead you to a maximum for n, depending on X and Y. :)
Luc Pattyn [My Articles] [Forum Guidelines]
Luc Pattyn wrote:
an algorithm that potentially takes forever is not really an algorithm
Yeah - it's .Net...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Luc Pattyn wrote:
an algorithm that potentially takes forever is not really an algorithm
Yeah - it's .Net...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001I am afraid you missed the point of the question, as well as of the first part of the solution. Maybe you can come up with the second half of the solution: an effective loop termination condition. Please keep in mind that so far no programming language or framework has been specified, and numeric variables have whatever capacity is required... And before you object, yes this topic should have been posted in Algo&Math forum rather than here. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }