Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace simplifyRadical
- {
- class Program
- {
- static string Radsimp(double x)
- {
- double rbase = 2;
- double coeff = 1;
- double sqr = 4;
- while (sqr <= x)
- {
- if ((x % sqr) == 0) {
- x /= sqr;
- coeff *= rbase;
- rbase = 2;
- } else {
- rbase++;
- sqr = Math.Pow(rbase, 2);
- }
- }
- if (x == 1)
- {
- return Convert.ToString(coeff);
- } else if (coeff == 1) {
- return "√" + Convert.ToString(x);
- } else {
- return Convert.ToString(coeff) + "√" + Convert.ToString(x);
- }
- }
- static void Main(string[] args)
- {
- while (true)
- {
- Console.WriteLine("Radical to simplify: ");
- try
- {
- var rad = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine(Radsimp(rad));
- } catch (SystemException) {
- Console.WriteLine("Invalid numeric entry.");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment