Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone,

I am new at Clojure and I am having a difficult time finding code examples as reference.
My assigment for my class is asking me to construct a code where we could enter powers (numbers and exponents). My C# code I constructed was this one:

C#
using System;

class AI_Assignment_1

{
   static string PowerProblemString(double x, double y)
   {
      double sum = Math.Pow (x, y);
      string sentence = x + " To The " + y + " Power Of Equals to " + sum;
      return sentence; 
   }
   static void Main()
   {
      Console.Write("Enter Your Base Number: ");
      double a = double.Parse(Console.ReadLine());
      Console.Write("Enter Your Exponent Number: ");
      double b = double.Parse(Console.ReadLine());
      Console.WriteLine(PowerProblemString(a, b));
   }
}

And here is my powers code I'm using for Clojure

(defn exp [x n]
     (if (zero? n) 1
         (* x (exp x (dec n)))))


What I have tried:

I'd simply would like to run the same program in Clojure where you could enter your number and exponent.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Feb-16 0:56am    
Languages are not learned by reading code samples. This is not a question. This is a request: "do the code translation for me". Why would we do that? It cannot help you.
—SA

1 solution

See Clojure[^].
 
Share this answer
 
Comments
jvaca1 8-Feb-16 14:18pm    
This is really good I am suprise they didn't include the site in the syllabus.

Sincerely Thank you
Richard MacCutchan 8-Feb-16 15:03pm    
You could have done what I did and use Google to find it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900