|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 as12350992 于 2020-11-29 23:37 编辑
Activity 4
Write a program to calculate the roots of a quadratic equation. A quadratic equation is an equation of the form:
ax^2+bx+c=0
The roots of a quadratic equation are given by the formula:
x=(-b±√(b^2-4ac))/2a
Your program should do the following:
1. Ask the user to enter values for a, b, and c. For example, print “a = ” to the console and then read the value for a.
2. Determine if the equation has 0, 1, or 2 roots. Print a message display the number of roots, for example: “The equation has 2 roots” or “The equation has 1 root” (Technically 1 solution is called a double root, but we’ll just call it 1 root for this activity).
3. Calculate and print the roots (if any). For a single root, print “r = <VALUE>”. For 2 roots, print “r1 = <VALUE>” on one line and “r2 = <VALUE>” on the next.
活动4
编写一个程序来计算二次方程的根。二次方程式为以下形式的方程式:
ax ^ 2 + bx + c = 0
二次方程的根由下式给出:
x =(-b±√(b ^ 2-4ac))/ 2a
您的程序应执行以下操作:
1.要求用户输入a,b和c的值。例如,在控制台上打印“ a =”,然后读取a的值。
2.确定方程式是否具有0、1、2的根。打印一条消息,显示根数,例如:“等式具有2个根”或“等式具有1个根”(技术上1个解称为双根,但在此活动中我们仅称其为1个根) 。
3.计算并打印根(如果有)。对于单个根,打印“ r = <VALUE>”。对于2个根,在一行上打印“ r1 = <VALUE>”,在下一行上打印“ r2 = <VALUE>”。 |
|