Guest User

Untitled

a guest
May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace simplifyRadical
  8. {
  9. class Program
  10. {
  11. static string Radsimp(double x)
  12. {
  13. double rbase = 2;
  14. double coeff = 1;
  15. double sqr = 4;
  16. while (sqr <= x)
  17. {
  18. if ((x % sqr) == 0) {
  19. x /= sqr;
  20. coeff *= rbase;
  21. rbase = 2;
  22. } else {
  23. rbase++;
  24. sqr = Math.Pow(rbase, 2);
  25. }
  26. }
  27. if (x == 1)
  28. {
  29. return Convert.ToString(coeff);
  30. } else if (coeff == 1) {
  31. return "√" + Convert.ToString(x);
  32. } else {
  33. return Convert.ToString(coeff) + "√" + Convert.ToString(x);
  34. }
  35. }
  36.  
  37. static void Main(string[] args)
  38. {
  39. while (true)
  40. {
  41. Console.WriteLine("Radical to simplify: ");
  42. try
  43. {
  44. var rad = Convert.ToDouble(Console.ReadLine());
  45. Console.WriteLine(Radsimp(rad));
  46. } catch (SystemException) {
  47. Console.WriteLine("Invalid numeric entry.");
  48. }
  49. }
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment