0% found this document useful (0 votes)
4 views13 pages

Utility Bill and Tax Calculations

Uploaded by

vmahescse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Utility Bill and Tax Calculations

Uploaded by

vmahescse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CO6 MEDIUM PROBLEM

1. Electricity Bill Calculation


#include <stdio.h>
int main() {
int units;
float bill = 0;
scanf("%d", &units);
if (units <= 100)
bill = units * 1.5;
else if (units <= 200)
bill = 100 * 1.5 + (units - 100) * 2.5;
else if (units <= 300)
bill = 100 * 1.5 + 100 * 2.5 + (units - 200) * 4;
else
bill = 100 * 1.5 + 100 * 2.5 + 100 * 4 + (units - 300) * 5;
printf("Total electricity bill %.2f\n", bill);
return 0;
}

2. Grade Based On Marks


#include <stdio.h>
int main() {
int marks;
scanf("%d", &marks);
if (marks >= 90)
printf("Grade A\n");
else if (marks >= 80)
printf("Grade B\n");
else if (marks >= 70)
printf("Grade C\n");
else if (marks >= 60)
printf("Grade D\n");
else
printf("Grade F\n");
return 0;
}

3. Monthly Loan EMI Calculation


#include <stdio.h>
#include <math.h>
int main() {
float P, annual_rate, n, r, EMI;
scanf("%f %f %f", &P, &annual_rate, &n);
r = annual_rate / (12 * 100);
n = n * 12;
EMI = (P * r * pow(1 + r, n)) / (pow(1 + r, n) - 1);
printf("Monthly EMI %.2f\n", EMI);
return 0;
}

4. Parking Fee Calculation


#include <stdio.h>
int main() {
int hrs;
float fee = 0;
scanf("%d", &hrs);
if (hrs <= 2)
fee = hrs * 5;
else if (hrs <= 5)
fee = 10 + (hrs - 2) * 4;
else if (hrs <= 10)
fee = 22 + (hrs - 5) * 3;
else
fee = 37 + (hrs - 10) * 2;
printf("Total parking charge %.2f\n", fee);
return 0;
}

5. Temperature Conversion Utility


#include <stdio.h>
int main() {
int choice;
float temp;
printf("Choose conversion type:\n1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\n");
scanf("%d", &choice);
if (choice == 1) {
scanf("%f", &temp);
printf("Temperature in Fahrenheit %.2fF\n", (temp * 9 / 5) + 32);
} else if (choice == 2) {
scanf("%f", &temp);
printf("Temperature in Celsius %.2fC\n", (temp - 32) * 5 / 9);
} else
printf("Invalid choice\n");
return 0;
}

6. Income Tax Calculation


#include <stdio.h>
int main() {
float income, tax = 0;
scanf("%f", &income);
if (income <= 10000)
tax = 0;
else if (income <= 20000)
tax = (income - 10000) * 0.1;
else if (income <= 50000)
tax = (10000) * 0.1 + (income - 20000) * 0.2;
else
tax = 10000 * 0.1 + 30000 * 0.2 + (income - 50000) * 0.3;
printf("Total tax payable %.2f\n", tax);
return 0;
}

7. ATM Withdrawal Notes


#include <stdio.h>
int main() {
int amount;
scanf("%d", &amount);
printf("500 notes %d\n", amount / 500);
amount %= 500;
printf("200 notes %d\n", amount / 200);
amount %= 200;
printf("100 notes %d\n", amount / 100);
amount %= 100;
printf("50 notes %d\n", amount / 50);
amount %= 50;
printf("20 notes %d\n", amount / 20);
amount %= 20;
printf("10 notes %d\n", amount / 10);
return 0;
}

8. Water Bill Calculation


#include <stdio.h>
int main() {
int gallons;
float bill = 0;
scanf("%d", &gallons);
if (gallons <= 1000)
bill = gallons * 1;
else if (gallons <= 2000)
bill = 1000 + (gallons - 1000) * 1.5;
else
bill = 1000 + 1000 * 1.5 + (gallons - 2000) * 2;
printf("Total water bill %.2f\n", bill);
return 0;
}

9. Salary Tax Calculation


#include <stdio.h>
int main() {
float salary, tax = 0;
scanf("%f", &salary);
if (salary <= 30000)
tax = 0;
else if (salary <= 60000)
tax = (salary - 30000) * 0.10;
else if (salary <= 100000)
tax = 30000 * 0.10 + (salary - 60000) * 0.20;
else
tax = 30000 * 0.10 + 40000 * 0.20 + (salary - 100000) * 0.30;
printf("Total tax payable %.2f\n", tax);
return 0;
}

10. BMI Classification


#include <stdio.h>
int main() {
float weight, height, bmi;
scanf("%f %f", &weight, &height);
bmi = weight / (height * height);
printf("BMI %.2f ", bmi);
if (bmi < 18.5)
printf("Underweight\n");
else if (bmi < 25)
printf("Normal weight\n");
else if (bmi < 30)
printf("Overweight\n");
else
printf("Obese\n");
return 0;
}

11. Loan Eligibility Check


#include <stdio.h>
#include <string.h>
int main() {
int age, salary;
char status[^20];
scanf("%d %d %s", &age, &salary, status);
if (age >= 21 && age <= 60 && salary > 25000 &&
(strcmp(status, "permanent") == 0 || strcmp(status, "contract") == 0))
printf("Eligible for loan\n");
else
printf("Not eligible for loan\n");
return 0;
}

12. Compound Interest Calculation


#include <stdio.h>
#include <math.h>
int main() {
float P, R, N, A;
scanf("%f %f %f", &P, &R, &N);
A = P * pow(1 + R / 100, N);
printf("Final amount %.2f\n", A);
return 0;
}

13. Triangle Type


#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
if (a == b && b == c)
printf("The triangle is Equilateral\n");
else if (a == b || a == c || b == c)
printf("The triangle is Isosceles\n");
else
printf("The triangle is Scalene\n");
} else {
printf("Invalid triangle\n");
}
return 0;
}

14. GCD Calculation (Euclidean Algorithm)


#include <stdio.h>
int main() {
int a, b, temp;
scanf("%d %d", &a, &b);
while (b != 0) {
temp = b;
b = a % b;
a = temp;
}
printf("GCD is %d\n", a);
return 0;
}
15. Fibonacci Series (do-while loop)
#include <stdio.h>
int main() {
int n, i = 2, a = 0, b = 1, c;
scanf("%d", &n);
if (n >= 1) printf("%d ", a);
if (n >= 2) printf("%d ", b);
do {
if (i >= n) break;
c = a + b;
printf("%d ", c);
a = b;
b = c;
i++;
} while (i < n);
return 0;
}

1. Electricity Bill Calculation


#include <stdio.h>
int main() {
int units;
float bill = 0;
scanf("%d", &units);
if (units <= 100) bill = units * 1.5;
else if (units <= 200) bill = 100 * 1.5 + (units - 100) * 2.5;
else if (units <= 300) bill = 100 * 1.5 + 100 * 2.5 + (units - 200) * 4;
else bill = 100 * 1.5 + 100 * 2.5 + 100 * 4 + (units - 300) * 5;
printf("Total electricity bill %.2f\n", bill);
return 0;
}

2. Student Grade
#include <stdio.h>
int main() {
int marks;
scanf("%d", &marks);
if (marks >= 90) printf("Grade A\n");
else if (marks >= 80) printf("Grade B\n");
else if (marks >= 70) printf("Grade C\n");
else if (marks >= 60) printf("Grade D\n");
else printf("Grade F\n");
return 0;
}

3. Loan Monthly EMI Calculation


#include <stdio.h>
#include <math.h>
int main() {
float P, R, N, r, EMI;
scanf("%f %f %f", &P, &R, &N);
r = R / (12 * 100);
N = N * 12;
EMI = (P * r * pow(1 + r, N)) / (pow(1 + r, N) - 1);
printf("Monthly EMI %.2f\n", EMI);
return 0;
}

4. Parking Fee Calculation


#include <stdio.h>
int main() {
int hrs;
float fee = 0;
scanf("%d", &hrs);
if (hrs <= 2) fee = hrs * 5;
else if (hrs <= 5) fee = 10 + (hrs - 2) * 4;
else if (hrs <= 10) fee = 22 + (hrs - 5) * 3;
else fee = 37 + (hrs - 10) * 2;
printf("Total parking charge %.2f\n", fee);
return 0;
}

5. Temperature Conversion Utility


#include <stdio.h>
int main() {
int choice;
float temp;
scanf("%d", &choice);
if (choice == 1) {
scanf("%f", &temp);
printf("Temperature in Fahrenheit %.2fF\n", temp * 9 / 5 + 32);
} else if (choice == 2) {
scanf("%f", &temp);
printf("Temperature in Celsius %.2fC\n", (temp - 32) * 5 / 9);
} else printf("Invalid choice\n");
return 0;
}

6. Tax Calculation
#include <stdio.h>
int main() {
float income, tax = 0;
scanf("%f", &income);
if (income <= 10000) tax = 0;
else if (income <= 20000) tax = (income - 10000) * 0.1;
else if (income <= 50000) tax = 10000 * 0.1 + (income - 20000) * 0.2;
else tax = 10000 * 0.1 + 30000 * 0.2 + (income - 50000) * 0.3;
printf("Total tax payable %.2f\n", tax);
return 0;
}

7. ATM Denomination Notes


#include <stdio.h>
int main() {
int amount;
scanf("%d", &amount);
printf("500 notes %d\n", amount / 500); amount %= 500;
printf("200 notes %d\n", amount / 200); amount %= 200;
printf("100 notes %d\n", amount / 100); amount %= 100;
printf("50 notes %d\n", amount / 50); amount %= 50;
printf("20 notes %d\n", amount / 20); amount %= 20;
printf("10 notes %d\n", amount / 10);
return 0;
}

8. Water Bill Calculation


#include <stdio.h>
int main() {
int gallons;
float bill = 0;
scanf("%d", &gallons);
if (gallons <= 1000) bill = gallons * 1;
else if (gallons <= 2000) bill = 1000 + (gallons - 1000) * 1.5;
else bill = 1000 + 1000 * 1.5 + (gallons - 2000) * 2;
printf("Total water bill %.2f\n", bill);
return 0;
}

9. Salary Tax Calculation


#include <stdio.h>
int main() {
float salary, tax = 0;
scanf("%f", &salary);
if (salary <= 30000) tax = 0;
else if (salary <= 60000) tax = (salary - 30000) * 0.10;
else if (salary <= 100000) tax = 30000 * 0.10 + (salary - 60000) * 0.20;
else tax = 30000 * 0.10 + 40000 * 0.20 + (salary - 100000) * 0.30;
printf("Total tax payable %.2f\n", tax);
return 0;
}

10. BMI Classification


#include <stdio.h>
int main() {
float weight, height, bmi;
scanf("%f %f", &weight, &height);
bmi = weight / (height * height);
printf("BMI %.2f ", bmi);
if (bmi < 18.5) printf("Underweight\n");
else if (bmi < 25) printf("Normal weight\n");
else if (bmi < 30) printf("Overweight\n");
else printf("Obese\n");
return 0;
}

11. Loan Eligibility Check


#include <stdio.h>
#include <string.h>
int main() {
int age, salary;
char status[^20];
scanf("%d %d %s", &age, &salary, status);
if (age >= 21 && age <= 60 && salary > 25000 &&
(strcmp(status, "permanent") == 0 || strcmp(status, "contract") == 0))
printf("Eligible for loan\n");
else printf("Not eligible for loan\n");
return 0;
}

12. Compound Interest Calculation


#include <stdio.h>
#include <math.h>
int main() {
float P, R, N, A;
scanf("%f %f %f", &P, &R, &N);
A = P * pow(1 + R / 100, N);
printf("Final amount %.2f\n", A);
return 0;
}

13. Triangle Type


#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
if (a == b && b == c)
printf("The triangle is Equilateral\n");
else if (a == b || a == c || b == c)
printf("The triangle is Isosceles\n");
else
printf("The triangle is Scalene\n");
} else {
printf("Invalid triangle\n");
}
return 0;
}

14. GCD (Euclidean Algorithm)


#include <stdio.h>
int main() {
int a, b, temp;
scanf("%d %d", &a, &b);
while (b != 0) {
temp = b;
b = a % b;
a = temp;
}
printf("GCD is %d\n", a);
return 0;
}

15. Fibonacci Series (do-while)


#include <stdio.h>
int main() {
int n, i = 2, a = 0, b = 1, c;
scanf("%d", &n);
if (n >= 1) printf("%d ", a);
if (n >= 2) printf("%d ", b);
do {
if (i >= n) break;
c = a + b;
printf("%d ", c);
a = b;
b = c;
i++;
} while (i < n);
return 0;
}

You might also like