需求:输入A数值范围映射出B数值范围,且A数值的中值不等于B数值的中值,也就是有比例系数偏移
已知:A数值范围,B数值范围,A数值的中值及其对应的B数值
#include
#include
using namespace std;
// 输入A数值范围映射出B数值范围
#define A_MIN 0
#define A_MAX 100
#define A_MID (A_MAX/2)
#define B_MIN 0
#define B_MAX 50
#define B_MID 30
// 比例系数1 (B_MID - (x - A_MID) / 10)
// 比例系数2 (B_MID + (A_MID - x) / 10)
// 此比例系数适用于B_MID值为20到30区间
int OutPutValue(int x)
{
if (x >= A_MID)
{
return (B_MID - (x - A_MID) / 10)*x / A_MID;
}
else
{
return (B_MID + (A_MID - x) / 10)*x / A_MID;
}
}
int main() {
int x_value,y_value;
printf("please input num:");
cin >> x_value; // 输入参数
y_value = OutPutValue(x_value);
printf("calculate output:");
cout << y_value; // 输出参数
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)