Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Classical Physics
Quantum Physics
Quantum Interpretations
Special and General Relativity
Atomic and Condensed Matter
Nuclear and Particle Physics
Beyond the Standard Model
Cosmology
Astronomy and Astrophysics
Other Physics Topics
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Classical Physics
Quantum Physics
Quantum Interpretations
Special and General Relativity
Atomic and Condensed Matter
Nuclear and Particle Physics
Beyond the Standard Model
Cosmology
Astronomy and Astrophysics
Other Physics Topics
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Astronomy and Cosmology
Astronomy and Astrophysics
C# Accurate Earth, Moon Sun visual model to predict eclipses
Reply to thread
Message
[QUOTE="jedishrfu, post: 6071194, member: 376845"] If you have code in one language and need it in another, its possible to convert it line by line. This requires understanding both languages enough to do that. However, sometimes it can be quite daunting especially if they are based on different paradigms. In the C to C# case, I don't think the port would be too difficult as they are both "C" style languages. Of course, you're probably going from procedural to object oriented but that is an easy mapping. To get an idea of what it might take look at the rosettacode.org site. They have many examples of tasks solved in a multitude of languages and while in many cases they are not direct ports of one another you can still see how things are done in C and then done in C#. Here's a list of C# examples, of which many have C versions too: [URL]http://rosettacode.org/wiki/Category:C_sharp[/URL] and here's Ackermans function as an example: [URL]http://rosettacode.org/wiki/Ackermann_function[/URL] and the C# code: [code=csharp] using System; class Program { public static long Ackermann(long m, long n) { if(m > 0) { if (n > 0) return Ackermann(m - 1, Ackermann(m, n - 1)); else if (n == 0) return Ackermann(m - 1, 1); } else if(m == 0) { if(n >= 0) return n + 1; } throw [URL='http://www.google.com/search?q=new+msdn.microsoft.com']new[/URL] System.ArgumentOutOfRangeException(); } static void Main() { for (long m = 0; m <= 3; ++m) { for (long n = 0; n <= 4; ++n) { Console.WriteLine("Ackermann({0}, {1}) = {2}", m, n, Ackermann(m, n)); } } } } [/code] and the C version: [code=c] #include <stdio.h> int ackermann(int m, int n) { if (!m) return n + 1; if (!n) return ackermann(m - 1, 1); return ackermann(m - 1, ackermann(m, n - 1)); } int main() { int m, n; for (m = 0; m <= 4; m++) for (n = 0; n < 6 - m; n++) [URL='http://www.opengroup.org/onlinepubs/009695399/functions/printf.html']printf[/URL]("A(%d, %d) = %d\n", m, n, ackermann(m, n)); return 0; } [/code] [/QUOTE]
Insert quotes…
Post reply
Forums
Astronomy and Cosmology
Astronomy and Astrophysics
C# Accurate Earth, Moon Sun visual model to predict eclipses
Back
Top