C# Sharp Conditional Statement : Exercises, Practice, Solution
C# Sharp Conditional Statement [25 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. 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
Click me to see the solution
2. 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
Click me to see the solution
3. Write a C# Sharp program to check whether a given number is positive or negative.
Test Data : 14
Expected Output :
14 is a positive number
Click me to see the solution
4. Write a C# Sharp program to find out whether a given year is a leap year or not.
Test Data : 2016
Expected Output :
2016 is a leap year.
Click me to see the solution
5. Write a C# Sharp program to read the age of a candidate and determine whether it is eligible for casting his/her own vote.
Test Data : 21
Expected Output:
Congratulation! You are eligible for casting your vote.
Click me to see the solution
6. Write a C# Sharp program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
Test Data : -5
Expected Output:
The value of n = -1
Click me to see the solution
7. Write a C# Sharp program to accept a person's height in centimeters and categorize them according to their height.
Test Data : 135
Expected Output :
The person is Dwarf.
Click me to see the solution
8. 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
Click me to see the solution
9. Write a C# Sharp program to accept a coordinate point in an XY coordinate system and determine in which quadrant the coordinate point lies.
Test Data :
Input the value for X coordinate :7
Input the value for Y coordinate :9
Expected Output :
The coordinate point (7,9) lies in the First quadrant.
Click me to see the solution
10. Write a C# Sharp program to determine the eligibility for admission to a professional course based on the following criteria:
Marks in Maths >=65
Marks in Phy >=55
Marks in Chem>=50
Total in all three subject >=180
or
Total in Math and Subjects >=140
Test Data :
Input the marks obtained in Physics :65
Input the marks obtained in Chemistry :51
Input the marks obtained in Mathematics :72
Expected Output :
The candidate is eligible for admission.
Click me to see the solution
11. Write a C# Sharp program to calculate the root of a quadratic equation.
Test Data :
Input the value of a : 1
Input the value of b : 5
Input the value of c : 7
Expected Output :
Root are imaginary;
No Solution.
Click me to see the solution
12. Write a C# Sharp program to read roll no, name and marks of three subjects and calculate the total, percentage and division.
Test Data :
Input the Roll Number of the student :784
Input the Name of the Student :James
Input the marks of Physics, Chemistry and Computer Application : 70 80 90
Expected Output :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
Division = First
Click me to see the solution
13. Write a C# Sharp program to read temperature in centigrade and display a suitable message according to the 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.
Click me to see the solution
14. Write a C# Sharp program to check whether a triangle is Equilateral, Isosceles or Scalene.
Test Data :
50 50 60
Expected Output :
This is an isosceles triangle.
Click me to see the solution
15. Write a C# Sharp program to check whether a triangle can be formed by the given angles value.
Test Data :
40 55 65
Expected Output :
The triangle is not valid.
Click me to see the solution
16. Write a C# Sharp program to check whether an alphabet letter is a vowel or a consonant.
Test Data :
k
Expected Output :
The alphabet is a consonant.
Click me to see the solution
17. Write a C# Sharp program to calculate profit and loss on a transaction.
Test Data :
500 700
Expected Output :
You can book your profit amount : 200
Click me to see the solution
18. Write a C# Sharp program to calculate and print the electricity bill of a customer. From the keyboard, the customer's name, ID, and unit consumed should be taken and displayed along with the total amount due.
The charge are as follow :
Unit | Charge/unit |
---|---|
upto 199 | @1.20 |
200 and above but less than 400 | @1.50 |
400 and above but less than 600 | @1.80 |
600 and above | @2.00 |
If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill should be of Rs. 100/-
Test Data :
1001
James
800
Expected Output :
Customer IDNO :1001
Customer Name :James
unit Consumed :800
Amount Charges @Rs. 2.00 per unit : 1600.00
Surchage Amount : 240.00
Net Amount Paid By the Customer : 1840.00
19. Write a program in C# Sharp to accept a grade and declare the equivalent description :
Grade | Description |
---|---|
E | Excellent |
V | Very Good |
G | Good |
A | Average |
F | Fail |
Test Data :
Input the grade :a
Expected Output :
You have chosen : Average
Click me to see the solution
20. Write a C# Sharp program to read any day number as an integer and display the name of the day as a word.
Test Data :
4
Expected Output :
Thursday
Click me to see the solution
21. Write a program in C# Sharp to read any digit, display in the word.
Test Data :
4
Expected Output :
Four
Click me to see the solution
22. Write C# Sharp program to read any Month Number in integer and display Month name.
Test Data :
4
Expected Output:
April
Click me to see the solution
23. Write a program in C# Sharp to read any Month Number in integer and display the number of days for this month.
Test Data :
7
Expected Output:
Month have 31 days
Click me to see the solution
24. Write a C# Sharp program that calculates the area of geometrical shapes using a menu-driven approach.
Test Data :
Input your choice : 1
Input radius of the circle : 5
Expected Output :
The area is : 78.500000
25. Write a program in C# Sharp which is a menu-driven program to perform simple calculations.
Test Date and Expected OutputEnter the first Integer :10
Enter the second Integer :2
Here are the options :
1-Addition.
2-Substraction.
3-Multiplication.
4-Division.
5-Exit.
Input your choice :3
The Multiplication of 10 and 2 is: 20
C# Sharp Code Editor:
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics