1. Home
  2. Docs
  3. C# Programming
  4. Question
  5. If-Else

If-Else

Write an if-statement that takes two integer variables and exchanges their values if the first one is greater than the second one.

Write a program that shows the sign (+ or -) of the product of three real numbers, without calculating it. Use a sequence of if operators.

Write a program that finds the biggest of three integers, using nested if statements.

Sort 3 real numbers in descending order. Use nested if statements.

Write a program that asks for a digit (0-9), and depending on the input, shows the digit as a word (in English). Use a switch statement.

Write a program that gets the coefficients a, b and c of a quadratic equation: ax2 + bx + c, calculates and prints its real roots (if they exist). Quadratic equations may have 0, 1 or 2 real roots.

Write a program that finds the greatest of given 5 numbers.

Write a program that, depending on the user’s choice, inputs int, double or string variable. If the variable is int or double, the program increases it by 1. If the variable is a string, the program appends “*” at the end. Print the result at the console. Use switch statement.

We are given 5 integer numbers. Write a program that finds those subsets whose sum is 0.

Examples:
– If we are given the numbers {3, -2, 1, 1, 8}, the sum of -2, 1 and 1 is 0.
– If we are given the numbers {3, 1, -7, 35, 22}, there are no subsets with sum 0.

Write a program that applies bonus points to given scores 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 an error message.

Write a program that converts a number in the range [0…999] to words, corresponding to the English pronunciation.

Examples:
– 0 –> “Zero”
– 12 –> “Twelve”
– 98 –> “Ninety eight”
– 273 –> “Two hundred seventy three”
– 400 –> “Four hundred”
– 501 –> “Five hundred and one”
– 711 –> “Seven hundred and eleven”

Was this article helpful to you? Yes No

How can we help?