Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.Exchange If Greater
- using System;
- //Write an if-statement that takes two integer variables a and b and exchanges their values if the first one is greater
- //than the second one. As a result print the values a and b, separated by a space. Examples:
- // a b result
- // 5 2 2 5
- // 3 4 3 4
- // 5.5 4.5 4.5 5.5
- class Program
- {
- static void Main()
- {
- double a = double.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- double r = 0;
- if (a > b)
- {
- r = a;
- a = b;
- b = r;
- Console.WriteLine("{0}<{1}",a,b);
- }
- else {
- Console.WriteLine(@"First value is lower!
- Is not change...");
- }
- }
- }
- // 2.Bonus Score
- using System;
- //Write a program that applies bonus score to given score in the range [1...9] by the following rules:
- //• If the score is between 1 and 3, the program multiplies it by 10.
- //• If the score is between 4 and 6, the program multiplies it by 100.
- //• If the score is between 7 and 9, the program multiplies it by 1000.
- //• If the score is 0 or more than 9, the program prints “invalid score”.
- //Examples:
- // score result
- // 2 20
- // 4 400
- // 9 9000
- // -1 invalid score
- // 10 invalid score
- class Program
- {
- static void Main()
- {
- int score = int.Parse(Console.ReadLine());
- int bonus = 0;
- if (score <= 0 || score > 9)
- {
- Console.WriteLine("Invalide score...");
- }
- else if (score > 0 && score <= 3)
- {
- bonus = score * 10;
- Console.WriteLine("Your BONUS is: " + bonus);
- }
- else if (score >= 4 && score <= 6)
- {
- bonus = score * 100;
- Console.WriteLine("Your BONUS is: " + bonus);
- }
- else if (score >= 7 && score <= 9)
- {
- bonus = score * 1000;
- Console.WriteLine("Your BONUS is: " + bonus);
- }
- }
- }
- //3.Check for a Play Card
- using System;
- //Classical play cards use the following signs to designate the card face: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K and A. Write a program that enters a string and prints “yes” if it is a valid card sign or “no” otherwise. Examples:
- //character Valid card sign?
- //5 yes
- //1 no
- //Q yes
- //q no
- //P no
- //10 yes
- //500 no
- class Program
- {
- static void Main()
- {
- string n = Console.ReadLine();
- string[] cards = new string[13] {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
- bool x = true;
- for (int i = 0; i < cards.Length; i++)
- {
- x = (n == cards[i])? true:false;
- }
- Console.WriteLine(!(x==true)?"yes":"no");
- }
- }
- //4.Multiplication Sign
- //Write a program that shows the sign (+, - or 0) of the product of three real numbers, without calculating it. Use a sequence of if operators. Examples:
- //a b c result
- //5 2 2 +
- //-2 -2 1 +
- //-2 4 3 -
- //0 -2.5 4 0
- //-1 -0.5-5.1 -
- class Program
- {
- static void Main()
- {
- int[] arr = new int[3];
- int x = 0;
- int r = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- if (arr[i] > 0)
- {
- x++;
- }
- else if (arr[i] < 0)
- {
- r++;
- }
- }
- if (x == 3)
- {
- Console.WriteLine("+");
- if (r == 3)
- {
- Console.WriteLine("-");
- }
- }
- if (x > r)
- {
- Console.WriteLine("-");
- }
- else if (x < r)
- {
- Console.WriteLine("+");
- }
- else if (x != r)
- {
- Console.WriteLine("0");
- }
- }
- }
- //5.The Biggest of 3 Numbers
- //Write a program that finds the biggest of three numbers. Examples:
- //a b c biggest
- //5 2 2 5
- //-2 -2 1 1
- //-2 4 3 4
- //0 -2.5 5 5
- //-0.1 -0.5 -1.1 -0.1
- class Program
- {
- static void Main()
- {
- double[] arr = new double[3];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = double.Parse(Console.ReadLine());
- if(arr[0]<arr[i])
- {
- arr[0] = arr[i];
- }
- }
- Console.WriteLine(arr[0]);
- }
- }
- //6.The Biggest of Five Numbers
- using System;
- //Write a program that finds the biggest of five numbers by using only five if statements. Examples:
- //a b c d e biggest
- //5 2 2 4 1 5
- //-2 -22 1 0 0 1
- //-2 4 3 2 0 4
- //0 -2.5 0 5 5 5
- //-3 -0.5 -1.1 -2 -0.1 -0.1
- class Program
- {
- static void Main()
- {
- decimal[] arr = new decimal[5];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = decimal.Parse(Console.ReadLine());
- if (arr[0] < arr[2])
- {
- arr[0] = arr[4];
- if (arr[0] < arr[1])
- {
- arr[0] = arr[1];
- if (arr[0] < arr[2])
- {
- arr[0] = arr[2];
- if (arr[0] < arr[3])
- {
- arr[0] = arr[3];
- }
- }
- }
- }
- }
- Console.WriteLine(arr[0]);
- }
- }
- //7.Sort 3 Numbers with Nested Ifs
- using System;
- //Write a program that enters 3 real numbers and prints them sorted in descending order. Use nested if statements. Don’t use arrays and the built-in sorting functionality. Examples:
- //a b c result
- //5 1 2 5 2 1
- //-2 -2 1 1 -2 -2
- //-2 4 3 4 3 -2
- //0 -2.5 5 5 0 -2.5
- //-1.1 -0.5 -0.1 -0.1 -0.5 -1.1
- class Program
- {
- static void Main()
- {
- double[] arr = new double[3];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = double.Parse(Console.ReadLine());
- }
- Array.Sort(arr);
- Array.Reverse(arr);
- foreach (double result in arr)
- {
- Console.WriteLine(result);
- }
- }
- }
- //8.Digit as Word
- using System;
- //Write a program that asks for a digit (0-9), and depending on the input, shows the digit as a word (in English). Print “not a digit” in case of invalid inut. Use a switch statement. Examples:
- //d result
- //2 two
- //1 one
- //0 zero
- //5 five
- //-0.1 not a digit
- //hi not a digit
- //9 nine
- //10 not a digit
- class Program
- {
- static void Main()
- {
- string d = Console.ReadLine();
- switch (d)
- {
- case "0":
- Console.WriteLine("zero");
- break;
- case "1":
- Console.WriteLine("one");
- break;
- case "2":
- Console.WriteLine("two");
- break;
- case "3":
- Console.WriteLine("three");
- break;
- case "4":
- Console.WriteLine("four");
- break;
- case "5":
- Console.WriteLine("five");
- break;
- case "6":
- Console.WriteLine("six");
- break;
- case "7":
- Console.WriteLine("seven");
- break;
- case "8":
- Console.WriteLine("eight");
- break;
- case "9":
- Console.WriteLine("nine");
- break;
- default:
- Console.WriteLine("not a diges");
- break;
- }
- }
- }
- //9.Play with Int, Double and String
- using System;
- //Write a program that, depending on the user’s choice, inputs an int, double or string variable. If the variable is int or double, the program increases it by one. If the variable is a string, the program appends "*" at the end. Print the result at the console. Use switch statement. Example:
- //program user program user
- //Please choose a type:
- //1 --> int
- //2 --> double
- //3 --> string 3 Please choose a type:
- //1 --> int
- //2 --> double
- //3 --> string 2
- //Please enter a string: hello Please enter a double: 1.5
- //hello* 2.5
- class Program
- {
- static void Main()
- {
- Console.WriteLine(@"Pleas choose a type:
- 1 ---> int
- 2 ---> double
- 3 ---> string");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- Console.WriteLine("Please enter a string:");
- int intInputUser = int.Parse(Console.ReadLine());
- Console.WriteLine(intInputUser);
- break;
- case "2":
- Console.WriteLine("Please enter a string:");
- double doubleInputUser = double.Parse(Console.ReadLine());
- Console.WriteLine(doubleInputUser);
- break;
- case "3":
- Console.WriteLine("Please enter a string:");
- string stringInputUser = Console.ReadLine();
- Console.WriteLine(stringInputUser);
- break;
- default:
- Console.WriteLine("Invalide input...");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment