鱼C论坛

 找回密码
 立即注册
查看: 1560|回复: 1

C++练习题

[复制链接]
发表于 2020-11-29 22:08:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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>”。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-11-30 21:48:39 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-11 20:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表