Complete C# Tutorial

C# Operators Practice Questions - Time to Code!

Hey there! Now that you’ve learned about C# operators, it’s time to put your skills to the test. No more just reading—you’ll write the code yourself! 🎉

Below are six practice questions, each focusing on different types of operators:

✅ Arithmetic Operators
✅ Comparison Operators
✅ Logical Operators
✅ Increment & Decrement Operators
✅ Assignment Operators
✅ Conditional Operator

Each question comes with an explanation, hints, and expected output.

No solutions this time—you’ll figure them out on your own! 💪

Let’s get started!

1️⃣ Arithmetic Operators – Grocery Bill Calculator 🛒

Question:

Imagine you’re at a grocery store buying apples, bananas, and oranges. Each item has a different price. Your task is to calculate the total bill before checkout.

📌 Hint:

  • Use the addition (+) operator to add up the item costs.
  • Use the multiplication (*) operator to calculate the total price for multiple items.

🖥 Expected Output:

				
					Total cost of groceries: $27
				
			

2️⃣ Comparison Operators – Who’s Older? 👶👴

Question:

You and your friend are curious to see who’s older. Write a program that compares your ages and tells who is older.

📌 Hint:

  • Use the greater than (>) and less than (<) operators to compare ages.
  • Print a message based on the comparison.

🖥 Expected Output:

				
					You are older than your friend.
				
			

3️⃣ Logical Operators – Exam Result Checker 📚

Question:

You need at least 40 marks to pass a subject. If you pass both subjects, you pass the exam. If you fail even one, you fail. Write a program to check if a student passes or fails.

📌 Hint:

  • Use the AND (&&) operator to check if both subjects are passed.
  • Print “Passed” if both conditions are true; otherwise, print “Failed.”

🖥 Expected Output:

				
					You passed the exam! 🎉				
			

4️⃣ Increment & Decrement Operators – Countdown Timer ⏳

Question:

Write a program that starts a countdown from 5 and decreases the number one by one until it reaches 0.

📌 Hint:

  • Use the decrement operator (–) inside a loop to count down.
  • Print each number as it decreases.

🖥 Expected Output:

				
					5
4
3
2
1
Time's up! 🚀				
			

5️⃣ Assignment Operators – Pocket Money Tracker 💰

Question:

You have $100 in your savings. Every month, you add $20 to it. Write a program that updates your savings for 3 months.

📌 Hint:

  • Use the += assignment operator to add money to savings.
  • Repeat this for 3 months.

🖥 Expected Output:

				
					Month 1: $120
Month 2: $140
Month 3: $160				
			

6️⃣ Conditional Operator – Odd or Even? 🔢

Question:

Write a program that asks for a number and checks if it’s odd or even using the conditional (ternary) operator.

📌 Hint:

  • Use the ternary operator (?:) to decide between “Even” and “Odd.”
  • A number is even if it’s divisible by 2 (use the modulus % operator).

🖥 Expected Output:

				
					Enter a number: 7
7 is Odd.				
			

Conclusion 🎯

Awesome job! You’ve made it through some fun C# operators practice questions. 🎉 These exercises helped you get comfortable with arithmetic, comparison, logical, assignment, and conditional operators. The more you practice, the better you get! 💪

If you got stuck, don’t worry—that’s part of learning! Take your time, try again, and soon, these operators will feel super easy. 😃

Next What? 🚀

You’ve mastered the basics, but guess what? There’s more! In the next chapter, we’re diving into Basic C# Statements such as (var, const, this, etc.)—the cool stuff that makes coding even more powerful. Get ready to level up your skills! 🔥

See you there! 🚀

Leave a Comment

Share this Doc

Programming exercises

Or copy link