Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Order of Ops 6.0 (Added Easy and Medium)
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using ShuffleExtension; using System.Threading; using System.Data; using MathSpace; using CountExtension; namespace Rextester { public class Program { public static void Main(string[] args) { makeOpQMed(); } public static void makeOpQEasy() { string fmt = "##;(-##)"; string[] op = new string[] {"+", "-", "*", "/"}; int numQ = 16; List<string>[] opQ = new List<string>[numQ]; for (int i = 0; i < numQ; i++){ opQ[i] = new List<string>(); } int result, count; decimal resultD; int countQ = 0; List<string> totalQ = new List<string>(); List<string> questions = new List<string>(); while(questions.Count()<120) { //for (int i=0; i<10000;i++) { int[] n = new int[3]; HashSet<int> numbers = new HashSet<int>(); while (numbers.Count < 3) { numbers.Add(Rand.NextPM(2,99)); // can change to Rand.Next(2,99) for positive integers or Rand.NextPM(2,99) for all integers } numbers.CopyTo(n); int a = Rand.Next(0,4); int b = Rand.Next(0,4); int c = Rand.Next(0,4); // 1st switch ++ switch(op[a]) { case "+": // 2nd switch +++ switch(op[b]) { case "+": result = n[0] + n[1] + n[2]; if (opQ[0].Count()<10 && Math.Abs(result)<100 ) { opQ[0].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] + n[1] - n[2]; if (opQ[1].Count()<10 && Math.Abs(result)<100 ) { opQ[1].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] + n[1] * n[2]; if (opQ[2].Count()<10 && Math.Abs(result)<100 ) { opQ[2].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] + ((decimal)n[1] /(decimal)n[2]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[3].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[3].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 1st switch break +++ case "-": // 2nd switch ++- switch(op[b]) { case "+": result = n[0] - n[1] + n[2]; if (opQ[4].Count()<10 && Math.Abs(result)<100 ) { opQ[4].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] - n[1] - n[2]; if (opQ[5].Count()<10 && Math.Abs(result)<100 ) { opQ[5].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] - n[1] * n[2]; if (opQ[6].Count()<10 && Math.Abs(result)<100 ) { opQ[6].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] - ((decimal) n[1] / (decimal)n[2]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[7].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[7].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 1st switch break ++- case "*": // 2nd switch ++* switch(op[b]) { case "+": result = n[0] * n[1] + n[2]; if (opQ[8].Count()<10 && Math.Abs(result)<100 ) { opQ[8].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] * n[1] - n[2]; if (opQ[9].Count()<10 && Math.Abs(result)<100 ) { opQ[9].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] * n[1] * n[2]; if (opQ[10].Count()<10 && Math.Abs(result)<100 ) { opQ[10].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = ((decimal) n[0] * n[1] / (decimal)n[2]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[11].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[11].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 1st switch break ++* case "/": // 2nd switch ++/ switch(op[b]) { case "+": resultD = ((decimal)n[0] /(decimal)n[1]) + n[2]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[12].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[12].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal)n[0] /(decimal)n[1]) - n[2]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[13].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[13].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = ((decimal)n[0] /(decimal)n[1]) * n[2]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[14].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[14].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) n[0] / (decimal)n[1] /(decimal)n[2]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[15].Count()<10 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[15].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 1st switch break ++/ } } // end while totalQ = questions.ToList(); totalQ.Shuffle(); string title1 = "Order of Operations"; string title2 = "Directed Numbers (Easy)"; string exerciseTitle = "Calculate the following questions"; Print(totalQ, title2, exerciseTitle, 20); PrintAnswerKey(totalQ, title2, 20); } public static void makeOpQMed() { string fmt = "##;(-##)"; string[] op = new string[] {"+", "-", "*", "/"}; int numQ = 64; List<string>[] opQ = new List<string>[numQ]; for (int i = 0; i < numQ; i++){ opQ[i] = new List<string>(); } int result, count; decimal resultD; int countQ = 0; List<string> totalQ = new List<string>(); List<string> questions = new List<string>(); while(questions.Count()<120) { //for (int i=0; i<10000;i++) { int[] n = new int[4]; HashSet<int> numbers = new HashSet<int>(); while (numbers.Count < 4) { numbers.Add(Rand.NextPM(2,99)); // can change to Rand.Next(2,99) for positive integers or Rand.NextPM(2,99) for all integers } numbers.CopyTo(n); int a = Rand.Next(0,4); int b = Rand.Next(0,4); int c = Rand.Next(0,4); switch(op[a]) { case "+": // 2nd switch ++ switch(op[b]) { case "+": // 3rd switch +++ switch(op[c]) { case "+": result = n[0] + n[1] + n[2] + n[3]; if (opQ[0].Count()<3 && Math.Abs(result)<100 ) { opQ[0].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] + n[1] + n[2] - n[3]; if (opQ[1].Count()<3 && Math.Abs(result)<100 ) { opQ[1].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] + n[1] + n[2] * n[3]; if (opQ[2].Count()<3 && Math.Abs(result)<100 ) { opQ[2].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] + n[1] + ((decimal)n[2] /(decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[3].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[3].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +++ case "-": // 3rd switch ++- switch(op[c]) { case "+": result = n[0] + n[1] - n[2] + n[3]; if (opQ[4].Count()<3 && Math.Abs(result)<100 ) { opQ[4].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] + n[1] - n[2] - n[3]; if (opQ[5].Count()<3 && Math.Abs(result)<100 ) { opQ[5].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] + n[1] - n[2] * n[3]; if (opQ[6].Count()<3 && Math.Abs(result)<100 ) { opQ[6].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] + n[1] - ((decimal) n[2] / (decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[7].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[7].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break ++- case "*": // 3rd switch ++* switch(op[c]) { case "+": result = n[0] + n[1] * n[2] + n[3]; if (opQ[8].Count()<3 && Math.Abs(result)<100 ) { opQ[8].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] + n[1] * n[2] - n[3]; if (opQ[9].Count()<3 && Math.Abs(result)<100 ) { opQ[9].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] + n[1] * n[2] * n[3]; if (opQ[10].Count()<3 && Math.Abs(result)<100 ) { opQ[10].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] + ((decimal) n[1] * n[2] / (decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[11].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[11].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break ++* case "/": // 3rd switch ++/ switch(op[c]) { case "+": resultD = n[0] + ((decimal)n[1] /(decimal)n[2]) + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[12].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[12].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = n[0] + ((decimal)n[1] /(decimal)n[2]) - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[13].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[13].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = n[0] + ((decimal)n[1] /(decimal)n[2]) * n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[14].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[14].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = n[0] + ((decimal) n[1] / (decimal)n[2] /(decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[15].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[15].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" + "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break ++/ } break; // 1st switch break ++ case "-": //2nd switch +- switch(op[b]) { case "+": // 3rd switch +-+ switch(op[c]) { case "+": result = n[0] - n[1] + n[2] + n[3]; if (opQ[16].Count()<3 && Math.Abs(result)<100 ) { opQ[16].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] - n[1] + n[2] - n[3]; if (opQ[17].Count()<3 && Math.Abs(result)<100 ) { opQ[17].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] - n[1] + n[2] * n[3]; if (opQ[18].Count()<3 && Math.Abs(result)<100 ) { opQ[18].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] - n[1] + ((decimal)n[2] / (decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[19].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[19].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +-+ case "-": // 3rd switch +-- switch(op[c]) { case "+": result = n[0] - n[1] - n[2] + n[3]; if (opQ[20].Count()<3 && Math.Abs(result)<100 ) { opQ[20].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] - n[1] - n[2] - n[3]; if (opQ[21].Count()<3 && Math.Abs(result)<100 ) { opQ[21].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] - n[1] - n[2] * n[3]; if (opQ[22].Count()<3 && Math.Abs(result)<100 ) { opQ[22].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] - n[1] - ((decimal)n[2] / (decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[23].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[23].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +-- case "*": // 3rd switch +-* switch(op[c]) { case "+": result = n[0] - n[1] * n[2] + n[3]; if (opQ[24].Count()<3 && Math.Abs(result)<100 ) { opQ[24].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] - n[1] * n[2] - n[3]; if (opQ[25].Count()<3 && Math.Abs(result)<100 ) { opQ[25].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] - n[1] * n[2] * n[3]; if (opQ[26].Count()<3 && Math.Abs(result)<100 ) { opQ[26].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] - ((decimal) (n[1] * n[2]) / (decimal)n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[27].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[27].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +-* case "/": // 3rd switch +-/ switch(op[c]) { case "+": resultD = n[0] - ( (decimal)n[1] / (decimal)n[2]) + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[28].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[28].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = n[0] - ((decimal) n[1] /(decimal) n[2]) - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[29].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[29].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = n[0] - ((decimal) n[1] /(decimal) n[2] * n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[30].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[30].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = n[0] - ((decimal)n[1] / (decimal)n[2]) / (decimal)n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[31].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[31].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" - "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +-/ } break; // 1st switch break +- case "*": //2nd switch +* switch(op[b]) { case "+": // 3rd switch +*+ switch(op[c]) { case "+": result = n[0] * n[1] + n[2] + n[3]; if (opQ[32].Count()<3 && Math.Abs(result)<100 ) { opQ[32].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] * n[1] + n[2] - n[3]; if (opQ[33].Count()<3 && Math.Abs(result)<100 ) { opQ[33].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] * n[1] + n[2] * n[3]; if (opQ[34].Count()<3 && Math.Abs(result)<100 ) { opQ[34].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] * n[1] + ((decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[35].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[35].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +*+ case "-": // 3rd switch +*- switch(op[c]) { case "+": result = n[0] * n[1] - n[2] + n[3]; if (opQ[36].Count()<3 && Math.Abs(result)<100 ) { opQ[36].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] * n[1] - n[2] - n[3]; if (opQ[37].Count()<3 && Math.Abs(result)<100 ) { opQ[37].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] * n[1] - n[2] * n[3]; if (opQ[38].Count()<3 && Math.Abs(result)<100 ) { opQ[38].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = n[0] * n[1] - ((decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[39].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[39].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +*- case "*": // 3rd switch +** switch(op[c]) { case "+": result = n[0] * n[1] * n[2] + n[3]; if (opQ[40].Count()<3 && Math.Abs(result)<100 ) { opQ[40].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "-": result = n[0] * n[1] * n[2] - n[3]; if (opQ[41].Count()<3 && Math.Abs(result)<100 ) { opQ[41].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "*": result = n[0] * n[1] * n[2] * n[3]; if (opQ[42].Count()<3 && Math.Abs(result)<100 ) { opQ[42].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+result+"\\)"); } break; case "/": resultD = ((decimal) n[0] * n[1] * n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[43].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[43].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +** case "/": // 3rd switch +*/ switch(op[c]) { case "+": resultD = ((decimal) n[0] * n[1] / (decimal) n[2]) + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[44].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[44].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal) n[0] * n[1] / (decimal) n[2]) - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[45].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[45].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = (decimal) n[0] * (decimal) n[1] / (decimal) n[2] * (decimal) n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[46].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[46].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) (n[0] * n[1]) / (decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[47].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[47].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\times "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +*/ } break; // 1st switch break +* case "/": //2nd switch +/ switch(op[b]) { case "+": // 3rd switch +/+ switch(op[c]) { case "+": resultD = ((decimal) n[0] / (decimal) n[1]) + n[2] + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[48].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[48].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal) n[0] / (decimal) n[1]) + n[2] - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[49].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[49].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = ((decimal) n[0] / (decimal) n[1]) + n[2] * n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[50].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[50].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) n[0] / (decimal) n[1]) + ((decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[51].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[51].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" + "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +/+ case "-": // 3rd switch +/- switch(op[c]) { case "+": resultD = ((decimal) n[0] / (decimal) n[1]) - n[2] + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[52].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[52].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal) n[0] / (decimal) n[1]) - n[2] - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[53].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[53].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = ((decimal) n[0] / (decimal) n[1]) - n[2] * n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[54].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[54].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) n[0] / (decimal) n[1]) - ((decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[55].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[55].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" - "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +/- case "*": // 3rd switch +/* switch(op[c]) { case "+": resultD = ((decimal) n[0] / (decimal) n[1] * n[2]) + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[56].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[56].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal) n[0] / (decimal) n[1] * n[2]) - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[57].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[57].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = ((decimal) n[0] / (decimal) n[1] * n[2] * n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[58].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[58].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) n[0] / (decimal) n[1] * (decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[59].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[59].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\times "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +/* case "/": // 3rd switch +// switch(op[c]) { case "+": resultD = ((decimal) n[0] / (decimal) n[1] / (decimal) n[2]) + n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[60].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[60].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" + "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "-": resultD = ((decimal) n[0] / (decimal) n[1] / (decimal) n[2]) - n[3]; count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[61].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[61].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" - "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "*": resultD = ((decimal) n[0] / (decimal) n[1] / (decimal) n[2] * n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[62].Count()<3 && count==0 && Math.Abs(resultD)<100 ) { opQ[62].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\times "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+resultD+"\\)"); } break; case "/": resultD = ((decimal) n[0] / (decimal) n[1] / (decimal) n[2] / (decimal) n[3]); count = BitConverter.GetBytes(decimal.GetBits(resultD)[3])[2]; if (opQ[63].Count()<3 && Math.Abs(resultD)<100 && resultD%1==0 && count==0 ) { opQ[63].Add(" "); questions.Add(" \\item \\(\\mathmakebox[4.25cm][l]{"+n[0].ToString(fmt)+" \\div "+n[1].ToString(fmt)+" \\div "+n[2].ToString(fmt)+" \\div "+n[3].ToString(fmt)+" }=\\underline{\\hspace{2cm}}\\)"+(int)resultD+"\\)"); } break; } break; // 2nd switch break +// } break; // 1st switch break +/ } // end switch } // end while totalQ = questions.ToList(); totalQ.Shuffle(); string title1 = "Order of Operations"; string title2 = "Directed Numbers (Medium)"; string exerciseTitle = "Calculate the following questions"; Print(totalQ, title2, exerciseTitle, 20); PrintAnswerKey(totalQ, title2, 20); } /***************************************************** /////////////////////LATEX CODES////////////////////// *****************************************************/ public static void PrintArithmetic<T>(List<T> list, string title) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{16pt}{25pt}\\selectfont", " \\setlength\\itemsep{10pt}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); //Console.WriteLine("\\subsection{Exercise "+(i/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine("\\subsection{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void PrintArithmetic<T>(List<T> list, string title, int questions) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{16pt}{25pt}\\selectfont", " \\setlength\\itemsep{10pt}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); //Console.WriteLine("\\subsection{Exercise "+(i/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%questions==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-33mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine("\\subsection{Exercise "+((i+questions)/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void Print<T>(List<T> list, string title, string exerciseTitle) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+(i/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+30)/30+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void PrintAnswerKey<T>(List<T> list, string title, int questions) { int p = 5; // number of pages before new page Console.WriteLine(); Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\newgeometry{"); Console.WriteLine(" a4paper,"); Console.WriteLine(" total={170mm,257mm},"); Console.WriteLine(" left=15mm,"); // 10mm for fractions Console.WriteLine(" top=20mm,"); Console.WriteLine(" bottom=20mm,"); Console.WriteLine(" right=15mm"); //10mm for fractions Console.WriteLine(" }"); Console.WriteLine("\\fontsize{10pt}{10pt}\\selectfont"); Console.WriteLine(); Console.WriteLine("\\section{"+title+" Answer Key}"); for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\textbf{p"+(i/questions+1)+"}"); Console.WriteLine(); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%(questions*p)==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\textbf{p"+((i+questions)/questions+1)+"}"); Console.WriteLine(); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } if (i!=0 && (i+1)%questions==0 && (i+1)%(questions*p)!=0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\textbf{p"+((i+questions)/questions+1)+"}"); Console.WriteLine("\\begin{multicols}{5}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); } } } public static void Print<T>(List<T> list, string title, string exerciseTitle, int questions) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+(i/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%questions==0){ Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+questions)/questions+1)+". "+exerciseTitle+".}"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void PrintFraction<T>(List<T> list, string title, string exerciseTitle) { //string title = "Title ()"; //string exerciseTitle = "Instructions"; //int m=0; //int i_final=30000; //int incre= 0; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{1.8em}"}; string[] op = new string[2] {"(", ")("}; //string end = ")=\\)"; for (int i=0; i<list.Count(); i++){ if(i==0){ Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine(latex[0]); Console.WriteLine("\\vspace{-5mm}\\subsection{Exercise "+(i/20+1)+". "+exerciseTitle+".}"); //Console.WriteLine("\\begin{tasks}(2)"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(list[i]); if (i!=0 && (i+1)%20==0){ //Console.WriteLine("\\end{tasks}"); Console.WriteLine(" \\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\newpage"); Console.WriteLine(); Console.WriteLine("\\begin{figure}[ht!]"); Console.WriteLine("\\vspace{-23mm}\\hspace*{-23mm}\\includegraphics[scale=0.9]{Logo.jpg}"); Console.WriteLine("\\end{figure}"); Console.WriteLine(); Console.WriteLine("\\vspace{-15mm}\\hspace*{-10mm}\\begingroup"); Console.WriteLine("\\centering"); Console.WriteLine("\\LARGE "+title+" \\\\[0.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); //Console.WriteLine(latex[0]); Console.WriteLine("\\subsection{Exercise "+((i+20)/20+1)+". "+exerciseTitle+".}"); //Console.WriteLine("\\begin{tasks}(2)"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static long GCD(long a, long b) { return b == 0 ? a : GCD(b, a % b); } public static long GCD(long a, long b, long c) { return GCD(a, GCD(b,c)); } public static int lcm(int a, int b) { int lcm; int a_r=a; int b_r=b; int d=max(a_r,b_r); while(d>1) { if (a_r%d==0 && b_r%d==0) { int a_r_temp=a_r/d; int b_r_temp=b_r/d; a_r=a_r_temp; b_r=b_r_temp; lcm=d*a_r*b_r; break; } d--; } return d*a_r*b_r; //Console.WriteLine("LCM({0},{1}): {2}", a,b,lcm); } public static int lcm(int a, int b, int c) { return lcm(a,lcm(b,c)); } public static int max(int a, int b) { if (a>b){ return a; } else if (b>a){ return b; } else { return a; } } public static int max(int a, int b, int c) { return max(a,max(b,c)); } public static int min(int a, int b) { if (a>b){ return b; } else if (b>a){ return a; } else { return a; } } public static int min(int a, int b, int c) { return min(a,min(b,c)); } public static void SimplifyRatio(int ratio1, int ratio2, int ratio3) { int divisor; if (ratio1>ratio2 && ratio1>ratio3) { divisor = ratio1; } else if (ratio2>ratio1 && ratio2>ratio3) { divisor = ratio2; } else divisor = ratio3; int ratio1_reduce = ratio1; int ratio2_reduce = ratio2; int ratio3_reduce = ratio3; while (divisor!=1) { if(ratio1_reduce%divisor==0 && ratio2_reduce%divisor==0 && ratio3_reduce%divisor==0){ int ratio1_reduce_temp = ratio1_reduce/divisor; int ratio2_reduce_temp = ratio2_reduce/divisor; int ratio3_reduce_temp = ratio3_reduce/divisor; ratio1_reduce = ratio1_reduce_temp; ratio2_reduce = ratio2_reduce_temp; ratio3_reduce = ratio3_reduce_temp; divisor--; } else divisor--; } Console.WriteLine(ratio1+":"+ratio2+":"+ratio3+" = "+ratio1_reduce+":"+ratio2_reduce+":"+ratio3_reduce); } } public static class Rand { /// <summary> /// Random number generator used to generate seeds, /// which are then used to create new random number /// generators on a per-thread basis. /// </summary> private static readonly Random globalRandom = new Random(); private static readonly object globalLock = new object(); /// <summary> /// Random number generator /// </summary> private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(NewRandom); /// <summary> /// Creates a new instance of Random. The seed is derived /// from a global (static) instance of Random, rather /// than time. /// </summary> public static Random NewRandom() { lock (globalLock) { return new Random(globalRandom.Next()); } } /// <summary> /// Returns an instance of Random which can be used freely /// within the current thread. /// </summary> public static Random Instance { get { return threadRandom.Value; } } /// <summary>See <see cref="Random.Next()" /></summary> public static int Next() { return Instance.Next(); } /// <summary>See <see cref="Random.Next(int)" /></summary> public static int Next(int maxValue) { return Instance.Next(maxValue); } /// <summary>See <see cref="Random.Next(int, int)" /></summary> public static int Next(int minValue, int maxValue) { return Instance.Next(minValue, maxValue); } public static int NextPM(int minValue, int maxValue) { // positive if (Rand.Next(0,2)==0) { return Instance.Next(minValue, maxValue); } else return -Instance.Next(minValue, maxValue); } /// <summary>See <see cref="Random.NextDouble()" /></summary> public static double NextDouble() { return Instance.NextDouble(); } /// <summary>See <see cref="Random.NextBytes(byte[])" /></summary> public static void NextBytes(byte[] buffer) { Instance.NextBytes(buffer); } public static double NextD(double minValue, double maxValue) { return Instance.NextDouble()*(maxValue-minValue)+minValue; } } } namespace ShuffleExtension { public static class ShuffleExtend { //private static readonly Random rnd = new Random(); public static void Shuffle<T>(this IList<T> list) { int n = list.Count; while (n > 1) { int k = (Rextester.Rand.Next(0, n) % n); n--; T value = list[k]; list[k] = list[n]; list[n] = value; } } } } namespace CountExtension { public static class CountExtension { public static int Count(this int n) { //return (Value == 0 ? 1 : ((int)Math.Floor(Math.Log10(Math.Abs(Value))) + 1)); return (n == 0 ? 1 : (int)Math.Log10(Math.Abs(n)) + 1); } } } namespace MathSpace { public struct Fraction { public long num; public long denom; public long integer; public long Num { get { return num; } set { num = value; } } public long Denom { get { return denom; } set { denom = value; } } public long Integer { get { return integer; } set { integer = value; } } public Fraction(int num, int denom) { // num + denom - if (num > 0 && denom < 0) { this.num = -num; this.denom = Math.Abs(denom); this.integer = 0; } // num - denom + else if (num < 0 && denom > 0 ) { this.num = -Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } // both positive or negative or zero else { this.num = Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } } public Fraction(long num, long denom) { // num + denom - if (num > 0 && denom < 0) { this.num = -num; this.denom = Math.Abs(denom); this.integer = 0; } // num - denom + else if (num < 0 && denom > 0 ) { this.num = num; this.denom = Math.Abs(denom); this.integer = 0; } // both positive or negative or zero else { this.num = Math.Abs(num); this.denom = Math.Abs(denom); this.integer = 0; } } public Fraction(int integer, int num, int denom) { if (num*denom<0) throw new ArgumentException("Numerator and Denominator must be positive."); // all + or only two + if (integer * num * denom > 0 ) { this.integer = Math.Abs(integer); this.num = Math.Abs(num); this.denom = Math.Abs(denom); } // if an odd - else { this.integer = -integer; this.num = Math.Abs(num); this.denom = Math.Abs(denom); } } public Fraction(long integer, long num, long denom) { if (num*denom<0) throw new ArgumentException("Numerator and Denominator must be positive."); // all + or only two + if (integer * num * denom > 0 ) { this.integer = Math.Abs(integer); this.num = Math.Abs(num); this.denom = Math.Abs(denom); } // if an odd - else { this.integer = -integer; this.num = Math.Abs(num); this.denom = Math.Abs(denom); } } public Fraction (Fraction left, int right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction (int left, Fraction right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction (Fraction left, Fraction right) { Fraction result = left/right; this.num = result.num; this.denom = result.denom; this.integer = 0; } public Fraction toMixed() { if (this.integer == 0 && (this.num < 0 || this.denom < 0)) { return new Fraction(this.num / this.denom, Math.Abs(this.num % this.denom), Math.Abs(this.denom)); } else if (this.integer == 0 && (this.num * this.denom > 0)) { return new Fraction(this.num / this.denom, this.num % this.denom, this.denom); } else return new Fraction(this.integer + this.num / this.denom, this.num % this.denom, this.denom); } public Fraction toImproper() { if (this.integer!=0 && this.integer<0) { return new Fraction (-(Math.Abs(this.integer)*Math.Abs(this.denom)+Math.Abs(this.num)),Math.Abs(this.denom)); } else if (this.integer!=0 && this.integer>0) { return new Fraction (Math.Abs(this.integer)*Math.Abs(this.denom)+Math.Abs(this.num),Math.Abs(this.denom)); } else return new Fraction (this.num,this.denom); } public override string ToString() { if (this.denom == 0) { return "Div by 0"; } // if fraction is proper or improper fraction if (this.denom != 1 && this.integer == 0 && this.num%this.denom!=0) { // if fraction is negative (either num or denom negative but not both) if ((this.num < 0 || this.denom < 0 ) && !(this.num<0 && this.denom<0) ) { this.denom = Math.Abs(this.denom); return this.num + "/" + this.denom; } // if fraction is positive else return num + "/" + denom; // + ", " + num/denom + " " + num%denom + "/" + denom; } //if fraction is mixed number else if (this.denom != 1 && this.integer != 0 && this.num%this.denom!=0) { var new_integer = Math.Abs(this.integer) + this.num/this.denom; var new_num = this.num % this.denom; this.integer = new_integer; this.num = new_num; // if fraction is negative (either num or denom negative but not both) if (this.integer < 0) { return this.integer + " " + this.num + "/" + this.denom; } // if fraction is positive else return this.integer + " " + this.num + "/" + this.denom; } // if denom not 1 and numerator is a multiple of the denominator (ie. 4/2 ==> 2) and not mixed number (result is integer) else if (this.num % this.denom == 0 && this.integer==0) { return (this.num / this.denom).ToString(); } // if denom not 1 and numerator is a multiple of the denominator (ie. 4/2 ==> 2) and mixed number (result is integer) else if (this.num % this.denom == 0 && this.integer!=0) { return (this.integer+(this.num / this.denom)).ToString(); } // if denominator is 1, ie., whole number and not mixed number else if (this.integer!=0) { return (integer+num).ToString(); } else return num.ToString(); } public Fraction Simplify() { int divisor = Convert.ToInt32(GCD(this.num, this.denom)); if (this.denom != 0 && this.integer==0 && this.num >0) { return new Fraction(this.num / divisor, this.denom / divisor); } else if (this.denom != 0 && this.integer==0 && this.num <0) { return new Fraction(-Math.Abs(this.num / divisor), Math.Abs(this.denom / divisor)); } else if (this.denom != 0 && this.integer!=0) { return new Fraction(this.integer, this.num / divisor, this.denom / divisor); } else return new Fraction (this.num, this.denom); } public static long GCD(long a, long b) { return b == 0 ? a : GCD(b, a % b); } public Fraction Reciprocal() { return new Fraction(this.Denom, this.Num); } public static Fraction operator +(Fraction left, Fraction right) { Fraction result; if (left.integer==0 &&right.integer==0){ result = new Fraction(left.num * right.denom + right.num * left.denom, left.denom * right.denom); } else { //result = new Fraction((left.integer*left.denom+left.num)*right.denom+(right.integer*right.denom+right.num)*left.denom, left.denom * right.denom); result = (new Fraction(left.integer+right.integer, left.num * right.denom + right.num * left.denom, left.denom * right.denom)).toMixed(); } return result.toMixed().Simplify(); } public static Fraction operator +(int left, Fraction right) { Fraction result; if (right.integer==0) { result = new Fraction(left * right.denom + right.num, right.denom); } else { result = (new Fraction(left+right.integer, right.num, right.denom)).toMixed(); } return result.Simplify(); } public static Fraction operator +(Fraction left, int right) { Fraction result; if (left.integer==0) { result = new Fraction(left.num + left.denom * right, left.denom); } else { result = (new Fraction(left.integer+right, left.denom)).toMixed(); } return result.Simplify(); } public static Fraction operator -(Fraction frac) { if (frac.integer==0) { return new Fraction(-frac.num,frac.denom); } else return (new Fraction (-frac.integer,frac.num,frac.denom)).toMixed(); } public static Fraction operator -(Fraction left, Fraction right) { Fraction result; if (left.integer==0 && right.integer==0) { result = (new Fraction(left.num * right.denom - right.num * left.denom, left.denom * right.denom)).toMixed(); } else { if (((left.integer*left.denom+left.num)/left.denom)>=((right.integer*right.denom+right.num)/right.denom)) { result = (left.toImproper()-right.toImproper()).toMixed(); } else result = (left.toImproper()-right.toImproper()).toMixed(); } return result.Simplify(); } public static Fraction operator -(int left, Fraction right) { Fraction result; if (right.integer==0) { result = new Fraction(left * right.denom - right.num, right.denom); } else result = (new Fraction(left * right.denom - right.toImproper().num, right.denom)).toMixed(); return result.Simplify(); } public static Fraction operator -(Fraction left, int right) { Fraction result; if (left.integer==0) { result = new Fraction(left.num - left.denom * right, left.denom); } // if mixed numbers else result = (new Fraction(left.toImproper().num - left.denom * right, left.denom)).toMixed(); return result.Simplify(); } public static Fraction operator *(Fraction left, Fraction right) { Fraction result; if (left.integer==0 && right.integer==0){ result = new Fraction(left.num * right.num, Math.Abs(left.denom * right.denom)); } // if mixed numbers else result = (left.toImproper()*right.toImproper()).toMixed(); return result.Simplify(); } public static Fraction operator *(int left, Fraction right) { Fraction result; if (right.integer==0){ result = new Fraction(left * right.num, right.denom); } else result = (new Fraction(right.toImproper().num * left, right.denom)).toMixed(); return result.Simplify(); } public static Fraction operator *(Fraction left, int right) { Fraction result; // if improper fraction if (left.integer==0){ result = new Fraction(left.num * right, left.denom); } // if mixed numbers else result = (new Fraction(left.toImproper().num * right, left.denom)).toMixed(); return result.Simplify(); } public static Fraction operator /(Fraction left, Fraction right) { Fraction result; if (left.integer==0 &&right.integer==0){ result = left * right.Reciprocal(); } else result = (left.toImproper() * right.toImproper().Reciprocal()).toMixed(); return result.Simplify(); } public static Fraction operator /(int left, Fraction right) { Fraction result; if (right.integer==0) { result = left * right.Reciprocal(); } else result = left * right.toImproper().Reciprocal(); return result.Simplify(); } public static Fraction operator /(Fraction left, int right) { Fraction rightRecip = new Fraction(1,right); Fraction result; if (left.integer==0) { result = left * rightRecip; } else { result = left.toImproper() * rightRecip; } return result.Simplify(); } public static int LCM(int a, int b) { int lcm; int a_r = a; int b_r = b; int d = max(a_r, b_r); while (d > 1) { if (a_r % d == 0 && b_r % d == 0) { int a_r_temp = a_r / d; int b_r_temp = b_r / d; a_r = a_r_temp; b_r = b_r_temp; lcm = d * a_r * b_r; break; } d--; } lcm = d * a_r * b_r; return lcm; } public static int LCM(long a, long b) { int lcm; long a_r = a; long b_r = b; int d = Convert.ToInt32(max(a_r, b_r)); while (d > 1) { if (a_r % d == 0 && b_r % d == 0) { long a_r_temp = a_r / d; long b_r_temp = b_r / d; a_r = a_r_temp; b_r = b_r_temp; lcm = Convert.ToInt32(d * a_r * b_r); break; } d--; } lcm = Convert.ToInt32(d * a_r * b_r); return lcm; } public static int max(int a, int b) { if (a > b) { return a; } else if (b > a) { return b; } else { return a; } } public static long max(long a, long b) { if (a > b) { return a; } else if (b > a) { return b; } else { return a; } } public double toDeci() { if (this.integer==0) { return (double) this.num/this.denom; } else { return (double) (this.integer*this.denom+this.num)/this.denom; } } public static Fraction toFrac(double deci) { /*List<double> d = new List<double>(); List<double> z = new List<double>(); List<double> n = new List<double>();*/ double[] d = new double[6]; double[] z = new double[6]; double[] n = new double[6]; z[1] = deci; //X d[0] = 0; d[1] = 1; for (int i = 1; i < 5; i++) { z[i + 1] = 1 / (z[i] - Math.Floor(z[i])); d[i + 1] = d[i] * Math.Floor(z[i + 1]) + d[i - 1]; n[i + 1] = Math.Round(z[1] * d[i + 1]); } int num, denom; num = (int)n[5]; denom = (int)d[5]; return new Fraction(num, denom); } public static Fraction Parse(string input) { if (String.IsNullOrWhiteSpace(input)) { throw new ArgumentNullException(); } //var instance = new Fraction(); // checks if there is more than one "/" if (input.IndexOf("/") != input.LastIndexOf("/")) { throw new ArgumentException(); } //return instance; int v; // if (input.IndexOf("/") != -1) { if (int.TryParse(input.Substring(0, input.IndexOf("/")), out v) && int.TryParse(input.Substring(input.IndexOf("/") + 1), out v)) { int num1 = int.Parse(input.Substring(0, input.IndexOf("/"))); int denom1 = int.Parse(input.Substring(input.IndexOf("/") + 1)); var frac = new Fraction(num1, denom1); return frac; } else throw new IndexOutOfRangeException(); } else // if { if (int.TryParse(input, out v)) { return new Fraction(int.Parse(input), 1); } else throw new IndexOutOfRangeException(); } } public static bool TryParse(string input, out Fraction frac) { if (string.IsNullOrWhiteSpace(input)) { frac = new Fraction(0, 0); return false; } if (input.IndexOf("/") == -1 || input.IndexOf("/") != input.LastIndexOf("/")) { frac = new Fraction(0, 0); return false; } long v; if (long.TryParse(input.Substring(0, input.IndexOf("/")), out v) && long.TryParse(input.Substring(input.IndexOf("/") + 1), out v)) { frac = new MathSpace.Fraction(1, 1); v = 1; return true; } else frac = new Fraction(0, 0); return false; } public static Fraction ConvertFrom(object obj) { Fraction frac = new MathSpace.Fraction(0, 0); if (obj.GetType() == frac.GetType()) { frac = (Fraction) obj; return frac; } else throw new NotSupportedException(); } public static double ConvertToDecimal(Fraction frac) { return Convert.ToDouble(frac.Num) / Convert.ToDouble(frac.Denom); } public static double operator +(Fraction left, double right) { double result = ConvertToDecimal(left) + right; return result; } public static double operator +(double left, Fraction right) { double result = left + ConvertToDecimal(right); return result; } public static double operator -(Fraction left, double right) { double result = ConvertToDecimal(left) - right; return result; } public static double operator -(double left, Fraction right) { double result = left - ConvertToDecimal(right); return result; } public static double operator *(Fraction left, double right) { double result = ConvertToDecimal(left) * right; return result; } public static double operator *(double left, Fraction right) { double result = left * ConvertToDecimal(right); return result; } public static double operator /(Fraction left, double right) { double result = ConvertToDecimal(left) / right; return result; } public static double operator /(double left, Fraction right) { double result = left / ConvertToDecimal(right); return result; } public static Fraction Pow(Fraction frac, int n) { long num_new = (long) Math.Pow(frac.Num, n); long denom_new = (long) Math.Pow(frac.Denom, n); return new MathSpace.Fraction(num_new, denom_new); } } }
run
|
edit
|
history
|
help
0
dynamic object
nested try catch
LCM and GCD
Linq join to tables
BitArrays Are Cool
30272 Program Ex5 if_else_odd_even
Fórum ➡ DataTable #1's rows that are NOT present in DataTable #2 ♦
Math 9.7 (Added Speed Math)
Watch Jurassic World Dominion Online Free
timeleft