using System; namespace Feb17 { class FractionPattern { //Input: the value of integer n where n is not divisible by 2 or 5 //Output: number of digits in the repeat pattern of fraction 1/n public static int PatternLength(int n) { //Initialization int length = 1; int power_of_ten = 10; int remainder = power_of_ten % n; //Continue to calculate until the remainder becomes 1 while(remainder != 1) { length ++; //Increment the length power_of_ten *= 10; //One more '0' for the dividend //Update the remainder with new dividend remainder = power_of_ten % n; // or "remainder = (int)(Math.Pow(10, length)) % 10" } return length; } public static void Main() { char choice; do { //Read in the input Console.Write("Please input an interger not divisible by 2 or 5: "); int n = int.Parse(Console.ReadLine()); //If if the input number is not divisible by 2 or 5 if((n % 2 != 0) && (n % 5 != 0)) { //output the pattern length Console.WriteLine("Length of repeat pattern is {0}", PatternLength(n)); //ask the user if repeat Console.Write("\nInput 'Y' to continue, 'N' to quit: "); choice = Console.ReadLine()[0]; } else { //The input number is divisible by 2 or 5. Ask for another input Console.WriteLine("\nInvalid input. Please try again. "); choice = 'Y'; } }while(choice == 'Y' || choice == 'y'); } } }