Problem Solving Using C#

Contents

Basic Problems

Basic Problem 1 - Add two numbers
Basic Problem 2 - Celsius to Fahrenheit
Basic Problem 3 - Elementary operations
Basic Problem 4 - Modulo operations
Basic Problem 5 - The cube of
Basic Problem 6 - Swap two numbers

Conditional Statements Problems

Conditional Statements Problem 1 - Absolute value
Conditional Statements Problem 2 - Divisible by 2 or 3

Basic Problem 1

Given three numbers, write a method that adds two first ones and multiplies them by a third one.

Basic Problem 2

Given a temperature in Celsius degrees, write a method that converts it to Fahrenheit degrees. Remember that temperature below -271.15°C (absolute zero) does not exist!
Expected input and output
CtoF(0) → "T = 32F"
CtoF(100) → "T = 212F"
CtoF(-300) → "Temperature below absolute zero!"

Basic Problem 3

Given two integers, write a method that returns results of their elementary arithmetic operations: addition, substraction, multiplication, division. Remember that you can't divide any number by 0!
Expected input and output
ElementaryOperations(3, 8) → 11, -5, 24, 0.375

Basic Problem 4

Given three integers, write a method that returns first number divided modulo by second one and these divided modulo by third one.
Expected input and output
ModuloOperations(8, 5, 2) → 1

Basic Problem 5

Given a number, write a method that returns its cube.
Expected input and output
TheCubeOf(2) → 8
TheCubeOf(-5.5) → -166.375

Basic Problem 6

Given two integers, write a method that swaps them using temporary variable.
Expected input and output
SwapTwoNumbers(87, 45) → "Before: a = 87, b = 45; After: a = 45, b = 87"
SwapTwoNumbers(-13, 2) → "Before: a = -13, b = 2; After: a = 2, b = -13"

Conditional Statements Problem 1

Given an integer, write a method that returns its absolute value.
Expected input and output
AbsoluteValue(6832) → 6832
AbsoluteValue(-392) → 392

Conditional Statements Problem 2

Given two integers, write a method that returns their multiplication if they are both divisible by 2 or 3, otherwise returns thier sum.
Expected input and output
DivisibleBy2Or3(15, 30) → 450
DivisibleBy2Or3(2, 90) → 180
DivisibleBy2Or3(7, 12) → 19