Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static Queue<Fraction> EgyptFraction(Fraction fr)
- {
- Queue<Fraction> q = new Queue<Fraction>();
- Fraction sum = new Fraction(0);
- int i = 2;
- while (sum != fr)
- {
- Fraction temp = new Fraction(1, i);
- while (sum + temp <= fr)
- {
- sum += temp;
- q.Enqueue(temp);
- }
- i++;
- }
- return q;
- }
- static void Main(string[] args)
- {
- Console.Write("Enter fraction: ");
- int[] input = Console.ReadLine().Split("/").Select(n => int.Parse(n)).ToArray(); ;
- Fraction fr = new Fraction(input[0], input[1]);
- Queue<Fraction> q = EgyptFraction(fr);
- while (q.Count != 0)
- {
- Console.Write("{0} ", q.Dequeue());
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement