Of course! I can help you with that. Here's a C function that calculates the output based on the provided table:
```c
#include <stdio.h>
double calculateOutput(double input) {
double output;
if (input < 1) {
output = input * 0.1;
} else if (input >= 1 && input <= 5) {
output = input * 0.2 - 0.1;
} else if (input > 5 && input <= 10) {
output = input * 0.3 - 0.6;
} else if (input > 10 && input <= 30) {
output = input * 0.4 - 1.6;
} else {
output = input * 0.5 - 4.6;
}
return output;
}
int main() {
double input = 15;
double output = calculateOutput(input);
printf("Input: %.1f\nOutput: %.1f\n", input, output);
return 0;
}
```
In the above code, the `calculateOutput` function takes an input value and applies the logic based on the provided table to calculate the output. The `main` function tests the `calculateOutput` function with an input of 15 and prints the input and output values. You can modify the `input` value in the `main` function to test with different values.
'C 언어' 카테고리의 다른 글
| 리습 1 (0) | 2024.05.06 |
|---|---|
| C 언어로 만든 Basic Interpreter (1) | 2024.01.21 |
| C언어로 Array of struct 만들기 (0) | 2023.07.04 |
| C언어로 만든 Hash Table (0) | 2023.05.12 |
| get_string 함수 (0) | 2022.10.20 |
댓글