gpt4 book ai didi

C++打印两个标志

转载 作者:行者123 更新时间:2023-11-28 05:57:00 25 4
gpt4 key购买 nike

<分区>

我只需要一点家庭作业的帮助。我正在编写一个程序来查找直线的斜率截距方程。 y = mx + b。问题是当 b 为负时,它打印的是 y=mx+-b,而不是 y=mx-b。谁能指出如何解决这个问题。

void get2_pt(double *x1, double *y1, double *x2, double *y2)
{

printf("Enter the x-y cordinates of the first point separated by a space =>\n");
scanf("%lf %lf", x1, y1);
printf("Enter the x-y cordinates of the second point separated by a space =>\n");
scanf("%lf %lf", x2, y2);

}
void slope_intcpt_from2_pt(double x1,
double y1,
double x2,
double y2,
double *m,
double *y_intcpt)
{

*m = (y2 - y1) / (x2 - x1);
*y_intcpt = y2 - (*m * x2);
}
void display2_pt(double x1, double y1, double x2, double y2)
{

printf("Two-point form\nm = (%0.2lf-%0.2lf) / (%0.2lf-%0.2lf)\n",
y2,
y1,
x2,
x1);

}
void display_slope_intcpt(double m, double y_intcpt)
{

printf("Entered Q4DSI\n");
printf("Slope-intercept form\ny = %0.2lfx + %0.2lf\n", m, y_intcpt);
}

int main()
{

double x1, x2, y1, y2, m, y_intcpt;
char again;
do
{

get2_pt(&x1, &y1, &x2, &y2);
slope_intcpt_from2_pt(x1, y1, x2, y2, &m, &y_intcpt);
display2_pt(x1, y1, x2, y2);
display_slope_intcpt(m, y_intcpt);

printf("Do another conversion (Y or N) =>\n");
scanf("%c", &again);
} while (again != 'N');
return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com