fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. int calcTotalTax(int n, long amounts[]) {
  5. int totalTax = 0;
  6.  
  7. for (int i = 0; i < n; i++) {
  8. if (amounts[i] > 1000) {
  9. // Calculate the taxable amount
  10. long taxableAmount = amounts[i] - 1000;
  11. // Calculate the tax (10% of the taxable amount)
  12. totalTax += taxableAmount / 10; // Integer division to ignore fractions
  13. }
  14. }
  15.  
  16. return totalTax;
  17. }
  18.  
  19. int main() {
  20. // Example test case
  21. long amounts[] = {1000, 2000, 3000, 4000, 5000};
  22. int n = 5;
  23. int totalTax = calcTotalTax(n, amounts);
  24. printf("%d\n", totalTax); // Output: 1000
  25.  
  26. // Additional test cases
  27. long test1[] = {1000}; // Expected output: 0
  28. long test2[] = {2000}; // Expected output: 100
  29. long test3[] = {3000, 4000, 5000}; // Expected output: 900
  30. long test4[] = {1500, 2500, 3500, 4500}; // Expected output: 800
  31. long test5[] = {0, 500, 1000}; // Expected output: 0
  32.  
  33. printf("%d\n", calcTotalTax(1, test1)); // Output: 0
  34. printf("%d\n", calcTotalTax(1, test2)); // Output: 100
  35. printf("%d\n", calcTotalTax(3, test3)); // Output: 900
  36. printf("%d\n", calcTotalTax(4, test4)); // Output: 800
  37. printf("%d\n", calcTotalTax(3, test5)); // Output: 0
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1000
0
100
900
800
0