



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




static void PrintSign(int number) { if (number > 0) Console.WriteLine("The number {0} is positive", number); else if (number < 0) Console.WriteLine("The number {0} is negative.", number); else Console.WriteLine("The number {0} is zero.", number); } static void Main() { PrintSign(int.Parse(Console.ReadLine())); } EXERCISE 2: public static void grade(double grades) { if (grades >=2.00&& grades <= 2.99) { Console.WriteLine("Fail"); } if (grades >= 3.00 && grades <= 3.49) Console.WriteLine("Poor"); if(grades >= 3.50 && grades <= 4.49) Console.WriteLine("Good"); if (grades >= 4.50 && grades <= 5.49) Console.WriteLine("Very good"); if (grades >= 5.50 && grades <= 6.00) Console.WriteLine("Exellent"); } static void Main(string[] args) { double grades=double.Parse(Console.ReadLine()); grade(grades); } EXERCISE 3: public static void Add(int a ,int b) { Console.WriteLine(a + b); } public static void Subtract(int a, int b) { Console.WriteLine(a- b); } public static void Devide(int a, int b) { Console.WriteLine(a / b); } public static void Multiply(int a, int b) { Console.WriteLine(a * b); } static void Main(string[] args) { string command=Console.ReadLine();
int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); switch (command) { case "Add": Add(a, b); break; case "Subtract": Subtract(a, b); break; case "Divide": Devide(a, b); break; case "Multiply": Multiply(a, b); break; } } EXERCISE 3: static void printNumbers(int start=0, int end=20) { //start = so bat dau // end so ket thuc for (int i = start; i <= end; i++) { Console.Write(i+" "); } Console.WriteLine(); } static void PrintTriangles(int n) { for (int line = 1; line <= n; line++) printNumbers(1, line); for (int Line = n-1; Line >= 1; Line--) { printNumbers(1, Line); } } static void Main(string[] args) { Console.WriteLine("Pleasae enter the hight of the triangle:"); int n = int.Parse(Console.ReadLine()); PrintTriangles(n); } EXERCISE 4: static void Main(string[] args) { string type = Console.ReadLine(); int quantity = int.Parse(Console.ReadLine()); Orders(type, quantity); }
string result =string.Empty; int firstsum = 0; int secondsum = 0; foreach(char c in first) { firstsum += c; } foreach(char c in second) { secondsum += c; } if (firstsum > secondsum) { result = first; } else { result = second; } Console.WriteLine(result); return result; } static char HigherThenTwo(char first, char second) { int result; if (first > second) { result=first; } else { result =second; } Console.WriteLine((char)result); return (char)result; } static int HigherThenTwo(int first, int second) { int result; if (first > second) { result = first; } else { result = second; } Console.WriteLine(result); return result; } static void Main(string[] args) { string command = Console.ReadLine(); if(command == "int") {
int first=int.Parse(Console.ReadLine()); int second=int.Parse(Console.ReadLine()); HigherThenTwo(first, second); } if (command == "char") { char a = char.Parse(Console.ReadLine()); char b = char.Parse(Console.ReadLine()); HigherThenTwo(a, b); } if (command == "string") { string s = Console.ReadLine(); string f = Console.ReadLine(); HigherThenTwo(s, f); } } EXERCISE 8: EXERCISE 9: EXERCISE 10: EXERCISE 11: