Apply for Zend Framework Certification Training

c

< Operators in C Predict output on Increment and Decrement Operators in C >




10 Hard Scenario-Based Problems on Operators in C
1. Smart Electricity Bill Calculator
Problem
A power company calculates an electricity bill based on units consumed:
First 100 units   → 2/unit
Next 200 units   → 3/unit
Next 300 units   → 5/unit
Above 600 units → 7/unit
If the total bill exceeds 2,000, add a 10% surcharge.
Add a fixed service charge of 100.
Use operators in C to calculate the final bill.
Test Cases
Input                Expected Output
50                    200.00
100                  300.00
250                  750.00
400                  1300.00
600                  2400.00
800                  4048.00
 
2. ATM Withdrawal Validation
Problem
An ATM accepts a withdrawal only when:
Amount is a multiple of 100.
Amount is greater than 0.
Amount does not exceed the account balance.
After withdrawal, at least 500 must remain.
ATM allows a maximum withdrawal of 20,000.
Print Approved or Rejected.
Test Cases
Balance        Amount         Output
10000          5000             Approved
10000          5500             Approved
10000          9600             Rejected
5000            4500             Approved
25000          20500           Rejected
3000            700              Rejected
 
3. Employee Bonus and Performance Evaluation
Problem
An employee receives a bonus based on:
Experience ≥ 5 years AND performance rating ≥ 8 → 20% bonus
Experience ≥ 3 years AND rating ≥ 6 → 10% bonus
Otherwise → 5% bonus
Additionally, employees with a salary above ?50,000 and rating below 5 receive no bonus.
Calculate the final salary.
Test Cases
Salary Experience Rating Output
40000 6               9        48000.00
50000 4               7        55000.00
30000 2               8        31500.00
60000 6               4        60000.00
45000 5               8        54000.00
70000 2               5        73500.00
 
4. Permission System Using Bitwise Operators
Problem
A system stores user permissions inside one integer.
Permission Value
Read 1
Write 2
Execute 4
Delete 8
Given a permission value, determine whether the user has:
Read permission
Write permission
Execute permission
Delete permission
Use bitwise operators.
Test Cases
Input Expected Output
1 Read: Yes, Write: No, Execute: No, Delete: No
2 Read: No, Write: Yes, Execute: No, Delete: No
3 Read: Yes, Write: Yes, Execute: No, Delete: No
5 Read: Yes, Write: No, Execute: Yes, Delete: No
12 Read: No, Write: No, Execute: Yes, Delete: Yes
15 Read: Yes, Write: Yes, Execute: Yes, Delete: Yes
 
5. Digital Wallet Transaction
Problem
A digital wallet has:
Current balance
Purchase amount
Cashback percentage
A transaction is valid only if:
Purchase amount > 0
Purchase amount ≤ balance
Purchase amount is a multiple of ?50
Cashback is:
10% if purchase ≥ ?5,000
5% if purchase ≥ ?2,000
Otherwise 2%
The cashback is added back to the wallet.
Calculate the final balance.
Test Cases
Balance Purchase Output
10000 5000 5500.00
10000 2000 8100.00
5000 1000 4020.00
3000 350 2657.00
3000 325 Invalid Transaction
2000 2500 Invalid Transaction
 
6. Network Packet Analyzer
Problem
A network packet contains a status byte.
The bits represent:
Bit 0 → Connected
Bit 1 → Authenticated
Bit 2 → Encrypted
Bit 3 → Priority
Bit 4 → Error
A packet is considered Secure when:
Connected
Authenticated
Encrypted
No Error
Use bitwise and logical operators.
Test Cases
Status Output
7 Secure
3 Not Secure
5 Not Secure
6 Not Secure
23 Not Secure
15 Secure
 
7. Online Shopping Discount Engine
Problem
An online store calculates discounts using:
Purchase ≥ ?10,000 → 20%
Purchase ≥ ?5,000 → 15%
Purchase ≥ ?2,000 → 10%
Otherwise → 5%
Extra conditions:
Premium customers receive an additional 5%.
If the customer has a coupon, an additional ?500 is deducted.
Maximum total discount percentage is 25%.
Calculate the final amount.
 
Test Cases
Amount Premium Coupon Output
10000 1 1 7500.00
10000 0 1 7500.00
6000 1 0 4800.00
4000 0 0 3600.00
1500 1 1 925.00
20000 1 1 14500.00
 
8. Student Result Analyzer
Problem
A student has marks in three subjects.
A student passes when:
Every subject ≥ 40
Average ≥ 50
Grades:
Average ≥ 80 → A
Average ≥ 70 → B
Average ≥ 60 → C
Average ≥ 50 → D
Otherwise → F
Additionally, if any subject is below 40, the student automatically fails.
Test Cases
Marks                Output
90 80 85            Pass - Grade A
75 72 70            Pass - Grade B
65 62 60            Pass - Grade C
55 50 52            Pass - Grade D
80 80 30            Fail
45 45 40            Fail
 
9. Temperature Monitoring System
Problem
A factory monitors machine temperature.
Classify the machine as:
Below 20°C → Cold
20–49°C → Normal
50–69°C → Warning
70–89°C → Critical
90°C or above → Emergency
However, if the cooling system is OFF and temperature is ≥ 70°C, immediately display Shutdown.
Use relational, logical, and conditional operators.
Test Cases
Temperature Cooling Output
15 1 Cold
30 1 Normal
55 1 Warning
75 1 Critical
95 1 Emergency
75 0 Shutdown
 
10. Bank Security Access Using Bitwise Operators
Problem
A bank's security system stores access privileges using bits:
Bit 0 → Employee
Bit 1 → Manager
Bit 2 → Admin
Bit 3 → Auditor
Bit 4 → Security Officer
Access to the confidential database is granted only when:
User is an employee AND
User is either a manager or admin AND
User is not an auditor
Determine whether access should be Granted or Denied.
Test Cases
Access Value            Binary Output
1      00001              Access Denied
3      00011              Access Granted
5      00101              Access Granted
9      01001              Access Denied
11    01011             Access Denied
7      00111              Access Granted
Operator Concepts Covered
Problem Main Operators
1. Electricity Bill Arithmetic, Relational, Conditional
2. ATM Arithmetic, Relational, Logical, Modulus
3. Employee Bonus Logical, Relational, Arithmetic
4. Permissions Bitwise AND, Shift, Conditional
5. Digital Wallet Modulus, Logical, Conditional
6. Network Packet Bitwise, Logical, Shift
7. Shopping Discount Conditional, Arithmetic, Logical
8. Student Result Relational, Logical, Conditional
9. Temperature Relational, Logical, Conditional
10. Bank Security Bitwise, Logical, Shift
 
These problems are designed to be harder than basic operator exercises because they combine multiple operators and require students to translate real-world conditions into C expressions.

< Operators in C Predict output on Increment and Decrement Operators in C >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top