C Online Compiler
Example: Income Tax Calculator in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Income Tax Calculator #include <stdio.h> int main() { double annual_income; double income_tax = 0.0; // Initialize tax to 0 // Step 1: Prompt user for annual income printf("Enter your annual taxable income (in PKR): "); scanf("%lf", &annual_income); // Step 2: Calculate income tax based on illustrative FBR-like slabs if (annual_income <= 600000) { income_tax = 0.0; // No tax for income up to 600,000 } else if (annual_income <= 1200000) { // Tax 2.5% on amount exceeding 600,000 income_tax = (annual_income - 600000) * 0.025; } else if (annual_income <= 1800000) { // Fixed tax for previous slab (600,000 * 2.5% = 15,000) // Plus 12.5% on amount exceeding 1,200,000 income_tax = 15000 + (annual_income - 1200000) * 0.125; } else if (annual_income <= 2500000) { // Fixed tax for previous slabs: // (600,000 * 2.5%) + (600,000 * 12.5%) = 15,000 + 75,000 = 90,000 // Plus 20% on amount exceeding 1,800,000 income_tax = 90000 + (annual_income - 1800000) * 0.20; } else { // Income > 2,500,000 // Fixed tax for previous slabs: // 90,000 + (700,000 * 20%) = 90,000 + 140,000 = 230,000 // Plus 25% on amount exceeding 2,500,000 income_tax = 230000 + (annual_income - 2500000) * 0.25; } // Step 3: Display the calculated income tax printf("Annual Taxable Income: PKR %.2lf\n", annual_income); printf("Calculated Income Tax: PKR %.2lf\n", income_tax); return 0; }
Output
Clear
ADVERTISEMENTS