Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Math
//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; namespace Rextester { public class Program { public int ratio1; public int ratio2; public int ratio3; public int num1, num2, num3; public static void Add(double num1, double num2 ) { double result = num1 + num2; Console.WriteLine(Convert.ToDouble(result)); } public static void Sub(double num1, double num2 ) { double result = num1 - num2; Console.WriteLine(Convert.ToDouble(result)); } public static void Mult(double num1, double num2 ) { double result = num1 * num2; Console.WriteLine(Convert.ToDouble(result)); } public static void Div(double num1, double num2 ) { if(num2==0) { Console.WriteLine(num1+"/"+num2+" = "+"Infinity"); } else { double result = num1 * (1/num2); Console.WriteLine(num1+"/"+num2+" = "+Convert.ToDouble(result)); } } public static double Fraction(double num, double denom) { double result = num*(1/denom); return result; } public static void showFraction(double num, double denom) { Console.WriteLine(Fraction(num,denom)); } //public static void addFraction( /* public static void LCM(int num1, int num2, int num3) { int lcm; int divisor; if (num1>n) (num1%num2==0 && num2%num3==0 && num3%num1==0) { lcm = num1*num2*num3; } }*/ /* public static void LCM(int num1, int num2) { int divisor; bool same_num; int lcm; if (num1>num2){ divisor=num1; lcm=1; same_num=false; } else if (num2>num1) { divisor=num2; lcm=1; same_num=false; } else { divisor=num1; lcm = num1; same_num=true; } int new_num1=num1; int new_num2=num2; int divisor_final=0; bool common_factor=false; while (divisor!=1 && same_num==false) { if(new_num1%divisor==0 && new_num2%divisor==0){ int new_num1_temp = new_num1/divisor; int new_num2_temp = new_num2/divisor; divisor_final = divisor; new_num1 = new_num1_temp; new_num2 = new_num2_temp; lcm = divisor_final*new_num1*new_num2; common_factor=true; divisor--; } else if (common_factor==false){ divisor--; divisor_final=divisor; lcm = divisor_final*new_num1*new_num2; } else divisor--; } Console.WriteLine("Dividends: "+num1+","+num2+"; LCM="+lcm); Console.WriteLine("Divisor: "+divisor_final+"; Reduced Quotients: "+new_num1+", "+new_num2); Console.WriteLine(" "); } */ public static void LCM(int a, int b) { int lcm; if (a==b) { Console.WriteLine("LCM : " + a); } else if (a>b) { if (a%b==0) { Console.WriteLine("LCM : " + a); } } else { for (int i=b; b>1; i--) { if (a%i==0 && b%i==0) { int a_reduced = a/i; int b_reduced = b/i; lcm = i*a_reduced*b_reduced; Console.WriteLine("LCM("+a+","+b+"): " + lcm); break; } } } } public static void LCM(int a, int b, int c) { int lcm; if (a==0) { Console.Write("LCM("+a+","+b+","+c+") = "); LCM(b,c); } else if (b==0) { Console.Write("LCM("+a+","+b+","+c+") = "); LCM(a,c); } else if(c==0) { Console.Write("LCM("+a+","+b+","+c+") = "); LCM(a,b); } // if all three are equal else if (a==b && b==c) { Console.WriteLine("LCM: "+a); } // if a and b are equal else if (a==b && a!=c) { if (a>c) { // if a is greater than c, use a as divisor then decrement for (int i=a; a>1; i--) { if (a%i==0 && c%i==0) { int a_reduced=a/i; int c_reduced=c/i; lcm = i*a_reduced*c_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } else { // if c is greater than a, use c as divisor then decrement for (int i=c; c>1; i--) { if (a%i==0 && c%i==0) { int a_reduced=a/i; int c_reduced=c/i; lcm = i*a_reduced*c_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } } // if b and c are equal else if (b==c && a!=b) { if (a>b) { // if a is greater than b, use b as divisor then decrement for (int i=a; a>1; i--) { if (a%i==0 && b%i==0) { int a_reduced=a/i; int b_reduced=b/i; lcm = i*a_reduced*b_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } else { // if b is greater than a, use b as divisor then decrement for (int i=b; b>1; i--) { if (a%i==0 && b%i==0) { int a_reduced=a/i; int b_reduced=b/i; lcm = i*a_reduced*b_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } } // if a and c are equal else if (a==c && a!=b) { if (a>b) { // if a is greater than b, use a as divisor then decrement for (int i=a; a>1; i--) { if (a%i==0 && b%i==0) { int a_reduced=a/i; int b_reduced=b/i; lcm = i*a_reduced*b_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } else { // if b is greater than a, use b as divisor then decrement for (int i=b; b>1; i--) { if (a%i==0 && b%i==0) { int a_reduced=a/i; int b_reduced=b/i; lcm = i*a_reduced*b_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } } //if all three are different else { int a_r = a; int b_r = b; int c_r = c; bool simplest = false; int d = max (a_r,b_r,c_r); //set divisor as the max of the 3 numbers while (d>1) { if (a_r%d==0 && b_r%d==0) { // simplest=false; Console.WriteLine("a_r and b_r"); break; } else if (a_r%d==0 && c_r%d==0) { // simplest=false; Console.WriteLine("a_r and c_r"); break; } else if (b_r%d==0 && c_r%d==0) { // simplest=false; Console.WriteLine("b_r and c_r"); break; } else { lcm=a_r*b_r*c_r; Console.WriteLine(d); Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); } d--; } while (simplest=false) { // if (a_r% } /* // a is largest if (a>b && a>c) { for(int i=a; i>1; i--) { // use a as divisor if (a%i==0 && b%i==0 && c%i!=0) { // if a and b are divisible but not c int a_reduced = a/i; int b_reduced = b/i; lcm = i*a_reduced*b_reduced*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (b%i==0 && c%i==0 && a%i!=0) { // if b and c are divisible but not a int b_reduced = b/i; int c_reduced = c/i; lcm = i*b_reduced*c_reduced*a; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && c%i==0 && b%i!=0) { // if a and c are divisible but not b int a_reduced = a/i; int c_reduced = c/i; lcm = i*a_reduced*c_reduced*b; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && b%i==0 && c%i==0) { // if all 3 are divisible int a_reduced = a/i; int b_reduced = b/i; int c_reduced = c/i; lcm = i*a_reduced*b_reduced*c_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else { // if only 1 is divisible lcm = a*b*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } // b is largest else if (b>a && b>c) { for(int i=b; i>1; i--) { // use b as divisor if (a%i==0 && b%i==0 && c%i!=0) { // if a and b are divisible but not c int a_reduced = a/i; int b_reduced = b/i; lcm = i*a_reduced*b_reduced*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (b%i==0 && c%i==0 && a%i!=0) { // if b and c are divisible but not a int b_reduced = b/i; int c_reduced = c/i; lcm = i*b_reduced*c_reduced*a; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && c%i==0 && b%i!=0) { // if a and c are divisible but not b int a_reduced = a/i; int c_reduced = c/i; lcm = i*a_reduced*c_reduced*b; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && b%i==0 && c%i==0) { // if all 3 are divisible int a_reduced = a/i; int b_reduced = b/i; int c_reduced = c/i; lcm = i*a_reduced*b_reduced*c_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else { // if only 1 is divisible lcm = a*b*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } } // c is largest else { for(int i=c; i>1; i--) { // use c as divisor if (a%i==0 && b%i==0 && c%i!=0) { // if a and b are divisible but not c int a_reduced = a/i; int b_reduced = b/i; lcm = i*a_reduced*b_reduced*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (b%i==0 && c%i==0 && a%i!=0) { // if b and c are divisible but not a int b_reduced = b/i; int c_reduced = c/i; lcm = i*b_reduced*c_reduced*a; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && c%i==0 && b%i!=0) { // if a and c are divisible but not b int a_reduced = a/i; int c_reduced = c/i; lcm = i*a_reduced*c_reduced*b; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else if (a%i==0 && b%i==0 && c%i==0) { // if all 3 are divisible int a_reduced = a/i; int b_reduced = b/i; int c_reduced = c/i; lcm = i*a_reduced*b_reduced*c_reduced; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } else { // if only 1 is divisible lcm = a*b*c; Console.WriteLine("LCM("+a+","+b+","+c+"): " + lcm); break; } } // c largest for loop } // c largest else*/ } } public static int max(int a, int b, int c) { if (a>=b && a>=c) { return a; } else if (b>=a && b>=c) { return b; } else { return c; } } public static void Pyth(int lowerBound, int upperBound) { //Your code goes here for (int i=lowerBound; i<=upperBound; i++) { for (int j=lowerBound; j<=upperBound; j++){ double c = Math.Sqrt(Math.Pow(i,2)+Math.Pow(j,2)); if (c%1==0){ Console.WriteLine("(a,b,c) = (" + i + "," + j + "," + 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 void makeSubQ(int firstLowerBound, int firstUpperBound, int secondLowerBound, int secondUpperBound){ for (int i=firstLowerBound; i<=firstUpperBound; i+=9){ for (int j=secondLowerBound; j<=secondUpperBound; j+=9){ if (i>j) { Console.WriteLine(" \\item \\("+i+"\\operation"+j+"=\\)"); } } } }*/ public static void makeSubQ(int firstLowerBound, int firstUpperBound, int secondLowerBound, int secondUpperBound){ string title = "Algebra Simplification Introduction"; string exerciseTitle = "Simplify the algebraic expressions"; 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 =")=\\)"; List<string> questions = new List<string>(); //for (int i=firstLowerBound; i<=firstUpperBound; i+=9){ for (int i=0; i<100;i++){ //for (int j=secondLowerBound; j<=secondUpperBound; j+=9){ for (int j=0; j<10;j++){ if (i>j) { questions.Add(" \\item \\("+i+"-"+j+"=\\)"); } } } questions.Shuffle(); //Console.WriteLine(questions.Count()); for (int i=0; i<questions.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("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.WriteLine(questions[i]); if (i!=0 && (i+1)%30==0){ Console.WriteLine(); Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); 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("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } } } public static void makeQ(int firstLowerBound, int firstUpperBound, int secondLowerBound, int secondUpperBound){ for (int i=firstLowerBound; i<=firstUpperBound; i+=9){ for (int j=secondLowerBound; j<=secondUpperBound; j+=9){ Console.WriteLine(" \\item \\("+i+"\\operation"+j+"=\\)"); } } } public static void makeDivQ(int firstLowerBound, int firstUpperBound, int secondLowerBound, int secondUpperBound){ for (int i=firstLowerBound; i<=firstUpperBound; i++){ for (int j=secondLowerBound; j<=secondUpperBound; j++){ if (i%j==0) { Console.WriteLine("\\("+i+"\\div"+j+"=\\)"); } } } } public static void addLineBreak(int linesPerSection, int totalLines) { for (int i=0; i<=totalLines; i++) { if (i%linesPerSection==0) { Console.WriteLine("Break"); } else Console.WriteLine("No"); } } public static void circleX(double x, double radius) { Console.WriteLine("("+x+", "+Math.Round(Math.Sqrt(radius*radius-Math.Pow(x,2)),3)+")"); } public static void circleY(double y, double radius) { Console.WriteLine("("+y+", "+Math.Round(Math.Sqrt(radius*radius-Math.Pow(y,2)),3)+")"); } public static void angle(double x1, double y1, double x2, double y2, double x3, double y3) { double l12 = Math.Pow((x1-x2),2) +Math.Pow((y1-y2),2); double l13 = Math.Pow((x3-x1),2) +Math.Pow((y3-y1),2); double l23 = Math.Pow((x3-x2),2) +Math.Pow((y3-y2),2); double lhs = (l13-l12-l23)/(-2*Math.Sqrt(l12)*Math.Sqrt(l23)); double angle2 = Math.Acos(lhs); //double angle2 = Math.Round(Math.Acos()*100,3); //Console.WriteLine(angle2 + " degrees C"); Console.WriteLine(l12 + " " + l23 + " " + l13); Console.WriteLine(lhs); Console.WriteLine(angle2*360/(2*Math.PI)+" degrees"); } public static void makeAlgebra(){ string[] vari = new string[24] {"a","b","c","d","f","g","h","k","m","n","p","q","r","s","t","u","v","w","x","y","z","\\delta", "\\epsilon", "\\phi"}; //var[0] = "a"; //var[1] = "b"; //var[2] = "c"; Random rand = new Random(); int n=-1; // n is the random number of variables per question int m=0; int i_final=30000; int incre= 0; string title = "Algebra Simplification Introduction"; string exerciseTitle = "Simplify the algebraic expressions"; string[] latex = new string[] {"\\fontsize{12pt}{16pt}\\selectfont", " \\setlength\\itemsep{2em}"}; string[] op = new string[2] {"(", ")("}; string end =")=\\)"; for (int i=1; i<=i_final; i++) { int num2=rand.Next(0,3); // range of number of different variables per question int num = rand.Next(2,5); // range of number of total variables per question int consts=rand.Next(1,6); // range of coefficients of the variables if(i==1){ 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("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } if (n==-1){ //first variable of each question Console.Write(" \\item \\("); } if (n==0){ Console.Write(consts+vari[num2+3*incre]+op[0]); } else if (n>0 && n<num){ Console.Write(consts+vari[num2+3*incre]+op[1]); } n++; if (n==num){ m++; Console.Write(consts+vari[num2+3*incre]); Console.Write(end); Console.WriteLine(); if (m%30==0) { incre=rand.Next(0,8); Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); 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("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.Write(" \\item \\("); n=0; } else if (n>num){ m++; Console.Write(consts+vari[num2+3*incre]); Console.Write(end); Console.WriteLine(); if (m%30==0) { incre=rand.Next(0,8); Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); Console.WriteLine(); Console.WriteLine("\\pagebreak[4]"); 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("\\large Promatics Education Centre\\\\[1.5em]"); Console.WriteLine("\\endgroup"); Console.WriteLine(); Console.WriteLine(latex[0]); Console.WriteLine("\\textbf{Exercise "+(m/30+1)+". "+exerciseTitle+".}\\\\"); Console.WriteLine("\\begin{multicols}{2}"); Console.WriteLine(" \\begin{enumerate}[label=\\arabic*)]"); Console.WriteLine(latex[1]); } Console.Write(" \\item \\("); n=0; } /* if(i==i_final){ Console.WriteLine("\\end{enumerate}"); Console.WriteLine("\\end{multicols}"); }*/ } } public static void makeDiv4by2() { Random rand = new Random(); for (int i =0; i<10000; i++) { int dividend = rand.Next(1001,10000); int divisor = rand.Next(11,99); if (dividend%divisor==0) { Console.WriteLine(" \\item \\("+dividend+"\\div"+divisor+"=\\)"); } } } public static void Main(String[] args){ //SimplifyRatio sr = new SimplifyRatio(2,4,8); //Console.WriteLine(sr.ratio1+":"+sr.ratio2+":"+sr.ratio3); /*SimplifyRatio(4,10,32); Div(1,Fraction(1,2)); LCM(12,6); LCM(6,7); LCM(2,3); LCM(10,120); Div(1,10); */ //showFraction(2,3); //makeDivQ(500,999,10,99); //addLineBreak(30,2108); //makeDivQ(1000,9999,1,9); //makeDivQ(10,99,5,9); //Console.WriteLine(max(0,0,1)); //Pyth(1,1000); //LCM(5,15,10); //circleX(-1.3,2); //makeAlgebra(); makeSubQ(10,100,10,100); } } } 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 = (rnd.Next(0, n) % n); n--; T value = list[k]; list[k] = list[n]; list[n] = value; } } } }
run
|
edit
|
history
|
help
0
test2
Intuit // C# // Lecture_4 // Laba_#2
How to use Lambda expression wiht generic delegate
Q: Why this calling base class virsion?
23
Unicode Braille Patterns.
Testing list
help sending dataGrid Rows to Access Table.
MightConst - Runtime Constwrapper Value (C#)
Simple Selection Sort