C#ArraysQuiz.md - brainchildservices/curriculum GitHub Wiki
A boolean expression evaluates to true or false.
Eg: a>b, c==10, d!=20 etc
if-else Statement if-else statements execute a given code path if some boolean expression is true and optionally execute a different code path if it is false. Use else if to specify a new condition to test, if the previous if condition or else if condition is false.
Example1:
https://dotnetfiddle.net/eUDKp9
Example2:
https://dotnetfiddle.net/xynsUv
Assignments:
C# Exercise: if....else & if..... else if ... else etc.
Q1. Write a C# Sharp program to accept two integers and check whether they are equal or not.
Test Data :
Input 1st number: 5
Input 2nd number: 5
Expected Output :
5 and 5 are equal
Q2: Write a C# Sharp program to check whether a given number is even or odd.
Test Data : 15
Expected Output :
15 is an odd integer
Q3: Write a C# Sharp program to find whether a given year is a leap year or not.
Test Data : 2016
Expected Output :
2016 is a leap year.
Q4: Write a C# Sharp program to find the largest of three numbers.
Test Data :
Input the 1st number :25
Input the 2nd number :63
Input the 3rd number :10
Expected Output :
The 2nd Number is the greatest among three
Q5: Write a C# Sharp program to read temperature in centigrade and display a suitable message according to temperature state below :
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
Q6: Write a C# Sharp program to check whether an alphabet is a vowel or consonant.
Test Data :
k
Expected Output :
The alphabet is a consonant.
Q7: Write a program to find the solutions of a quadratic equation:
Hint: Quadratic equation is a second-order polynomial equation expressed in a single variable, x, with a ≠ 0: ax2+bx+c=0 and has two roots
First find the discriminant using the formula: disc = b * b – 4 * a * c.
case 1: If a=0: The roots are Linear: x1=-c / b
Case 2: If a not equal 0 and disc > 0
THE ROOTS ARE REAL AND DISTINCT ROOTS:
x1 = (-b+√(b²-4ac))/(2a)
x2 = (-b-√(b²-4ac))/(2a)
Case3 : If a not equal 0 and disc = 0
THE ROOTS ARE REPEATED ROOTS
x1=x2=-b / 2a
Case4 : If a not equal 0 and disc > 0
THE ROOTS ARE IMAGINARY ROOTS
Test Data:
ENTER THE VALUES OF A,B,C...
4
2
0
THE ROOTS ARE REAL AND DISTINCT ROOTS THE ROOTS ARE... 0 and -0.5
Q8: Write a program to take a weekday number from the user and accordingly print the day of the week.
Test Data :
Enter a weekday number: 5
Expected Output :
Its Thursday.
Q9: Write a program to take a month number from the user and accordingly print the month of the year.
Test Data :
Enter a month number: 3
Expected Output :
Its March.
Q10: Write a program that takes 2 numbers from the user. Next the user is asked to enter any of the arithmetic operator(+,-,*,/). Based on the arithmetic operator entered the user should be displayed the result of number1 and number 2
Test Data:
Enter number 1: 10
Enter number 2: 5
Enter arithmetic operator: /
Expected Output :
The quotient of 10 divided by 5 is 2