Programs to calculate the income tax on given income are shown here. The income tax is calculated according to the income obtained by an employee. The following table depicts the tax rate and the ranges of income.

Income Tax Rate
Upto 250000 Nil.
250001 to 500000 5% of income exceeding 250000
500001 to 1000000 12500 + 20% of income exceeding 500000
Above 1000000 112500 + 30% of income exceeding 1000000

For example, if the income is 750000, then according to the table, the income tax would be calculated as:

12500 + 20 % of (750000 - 500000)

=> 12500 + 20 % of 250000

=> 12500 + 50000

=> 62500

## 1. Algorithm to calculate income tax

1. Take the income x as input.

2. If x <= 250000, tax would be 0.

3. If 250001 <= x <= 500000, tax would be 5% of (x - 250000).

4. If 500001 <= x <= 1000000, tax would be 12500 + 20% of (x - 500000).

5. If x > 1000000, tax would be 112500 + 30% of (x - 1000000).

## 2. Pseudocode to calculate income tax

Input : Income $i$

Output : Income tax on $i$

1. Procedure incomeTax($i$):

2. If $i \leq 250000$:

3. Return $0$

4. Else If $i \leq 500000$:

5. Return $(i - 250000) * 0.05$

6. Else If $i \leq 1000000$:

7. Return $12500 + (i - 500000) * 0.2$

8. Else:

9. Return $112500 + (i - 1000000) * 0.3$

10. End Procedure

## 3. Time complexity to calculate income tax

Time Complexity: O(1)

## 4. Program to calculate income tax

In this section, the C, C++, Java, Python and C# programs to calculate income tax w.r.t the given income are given.

## 4.1. C Program to calculate income tax

Code has been copied
/*********************************
alphabetacoder.com
C program to calculate income tax
**********************************/
#include <stdio.h>

int main() {
// declare variables
double income, tax = 0;

// take input
printf("Enter the income: ");
scanf("%lf", & income);

// find the income tax
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = (income - 250000) * 0.05;
} else if (income <= 1000000) {
tax = 12500 + (income - 500000) * 0.2;
} else {
tax = 112500 + (income - 1000000) * 0.3;
}

// display income tax
// upto 2 decimal places
printf("Income tax: %0.2lf", tax);

return 0;
}

Output

#### Case 1:

Enter the income: 377000

Income tax: 6350.00

#### Case 2:

Enter the income: 232770

Income tax: 0.00

#### Case 3:

Enter the income: 1120000

Income tax: 148500.00

## 4.2. C++ Program to calculate income tax

Code has been copied
/***********************************
alphabetacoder.com
C++ program to calculate income tax
************************************/

#include <iostream>

using namespace std;

int main() {
// declare variables
double income, tax = 0;

// take input
cout << "Enter the income: ";
cin >> income;

// find the income tax
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = (income - 250000) * 0.05;
} else if (income <= 1000000) {
tax = 12500 + (income - 500000) * 0.2;
} else {
tax = 112500 + (income - 1000000) * 0.3;
}

// display income tax
// upto 2 decimal places
cout.precision(2);
cout << "Income tax: " << fixed << tax;

return 0;
}

Output

#### Case 1:

Enter the income: 1247567

Income tax: 186770.10

#### Case 2:

Enter the income: 766550

Income tax: 65810.00

#### Case 3:

Enter the income: 400000

Income tax: 7500.00

## 4.3. Java Program to calculate income tax

Code has been copied
/************************************
alphabetacoder.com
Java program to calculate income tax
*************************************/

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
// declare variables
double income, tax = 0;

// declare an instance of scanner class
Scanner sc = new Scanner(System.in);

// take input
System.out.print("Enter the income: ");
income = sc.nextDouble();

// find the income tax
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = (income - 250000) * 0.05;
} else if (income <= 1000000) {
tax = 12500 + (income - 500000) * 0.2;
} else {
tax = 112500 + (income - 1000000) * 0.3;
}

// display income tax
// upto 2 decimal places
System.out.print("Income tax: " + ((int)(tax * 100)) / 100.0);
}
}

Output

#### Case 1:

Enter the income: 1233333

Income tax: 182499.9

#### Case 2:

Enter the income: 894500

Income tax: 91400.00

#### Case 3:

Enter the income: 150000

Income tax: 0.0

## 4.4. Python Program to calculate income tax

Code has been copied
# ***************************************
#           alphabetacoder.com
# Python program to calculate income tax
# ***************************************

# take input
income = float(input("Enter the income: "))

# find the income tax
if income <= 250000:
tax = 0
elif income <= 500000:
tax = (income - 250000) * 0.05
elif income <= 1000000:
tax = 12500(income - 500000) * 0.2
else:
tax = 112500(income - 1000000) * 0.3

# display income tax
# upto 2 decimal places
print("Income tax: ", round(tax, 2))

Output

#### Case 1:

Enter the income: 654000

Income tax: 43300.0

#### Case 2:

Enter the income: 1100000

Income tax: 142500.0

#### Case 3:

Enter the income: 999999

Income tax: 112499.8

## 4.5. C# Program to calculate income tax

Code has been copied
/**********************************
alphabetacoder.com
C# program to calculate income tax
***********************************/

using System;

namespace IncomeTax {
class Program {
static void Main(string[] args) {
// declare variables
double income, tax = 0;

// take input
Console.Write("Enter the income: ");

// find the income tax
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = (income - 250000) * 0.05;
} else if (income <= 1000000) {
tax = 12500 + (income - 500000) * 0.2;
} else {
tax = 112500 + (income - 1000000) * 0.3;
}

// display income tax
// upto 2 decimal places
Console.WriteLine("Income tax: " + Math.Round(tax, 2));

// wait for user to press any key
}
}
}

Output

#### Case 1:

Enter the income: 2000000

Income tax: 412500

#### Case 2:

Enter the income: 190000

Income tax: 0

#### Case 3:

Enter the income: 797450

Income tax: 71990