Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MyClassLibrary
- {
- public class Fraction
- {
- static public string ToString(double numeric)
- {
- string result = "";
- bool otr = false;
- if (numeric < 0)
- {
- otr = true;
- numeric = numeric * (-1);
- }
- int ind = numeric.ToString().IndexOf(',');
- if (ind == -1)
- return numeric.ToString();
- ulong cile = ulong.Parse(numeric.ToString().Substring(0, ind));
- ulong chisel = ulong.Parse(numeric.ToString().Remove(0, ind + 1));
- ulong znam = 1;
- for (int i = 0; i < chisel.ToString().Length; i++)
- znam *= 10;
- for (ulong i = 2; i < znam; i++)
- {
- if (chisel % i == 0 && znam % i == 0)
- {
- chisel /= i;
- znam /= i;
- i = 1;
- }
- }
- result = (cile * znam + chisel).ToString() + "/" + znam.ToString();
- if (otr)
- {
- result = "-" + result;
- }
- return result;
- }
- static public string Sokr()
- {
- Console.WriteLine("Введіть чисельник");
- int сh = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введіть знаменник");
- int zn = Convert.ToInt32(Console.ReadLine());
- int nod = 0;
- for (int i = 1; i < (сh * zn + 1); i++)
- {
- if (zn % i == 0 && сh % i == 0)
- {
- nod = i;
- }
- }
- сh = сh / nod;
- zn = zn / nod;
- string strCh = Convert.ToString(сh);
- string strZn = Convert.ToString(zn);
- string s = strCh + "/" + strZn;
- Console.WriteLine(s);
- return s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement