Advertisement
Guest User

test#v1

a guest
Nov 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. /*
  2. Digit cancelling fractions
  3.  
  4. The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
  5.  
  6. We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
  7.  
  8. There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
  9.  
  10. If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
  11.  *
  12.  * (10*a + b)/(10*b + c) = a / c
  13.  * a * (10 * b + c) = c * (10 * a + b)
  14.  * and
  15.  * a =/= b =/= c
  16.  * we have a digit cancelling fraction
  17. */
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Diagnostics;
  24.  
  25. namespace home_project
  26. {
  27.     class Program
  28.     {
  29.         static void Main(string[] args)
  30.         {
  31.             Stopwatch sw = new Stopwatch();
  32.             sw.Start();
  33.             float final_nom = 1;
  34.             float final_denom = 1;
  35.             for (float a = 1; a < 10; a++)
  36.             {
  37.                 for (float b = a; b < 10; b++)
  38.                 {
  39.                     for (float c = 1; c < 10; c++)
  40.                     {
  41.                         float nom = a * 10 + b;
  42.                         float denom = b * 10 + c;
  43.                         if (nom < denom)
  44.                         {
  45.                             if ( (nom / denom) == (a / c))
  46.                             {
  47.                                 final_nom = nom;
  48.                                 final_denom = denom;
  49.  
  50.                                 Console.WriteLine("Conditions are fullfilled for this fraction:\n" + final_nom + " / " + final_denom + "\nProof: " + final_nom + " / " + final_denom + " = " + nom / denom + " & " + a + " / " + c + " = " + nom / denom);
  51.                             }
  52.                         }
  53.  
  54.                     }
  55.                 }
  56.             }
  57.             sw.Stop();
  58.             Console.WriteLine("Problem completed in {0}ms", sw.ElapsedMilliseconds);
  59.             Console.ReadKey();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement