SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Anany Levitin
Chapter:
Introduction
Exercise:
1.2 Exercise
Question:4 | ISBN:9780132316811 | Edition: 3

Question

Write pseudocode for an algorithm for finding real roots of equation ax^2 +bx + c = 0 for arbitrary real coefficients a, b, and c. (You may assume the availability of the square root function sqrt (x).)

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

  • let d = b * b - 4 * a * c 
  • if d < 0 then 
  • print "No real roots." 
  • else if d = 0 then 
  • print "Root is: "; -b / (2 * a); "." 
  • else 
  • print "Roots are: "; (-b + sqrt ( d )) / (2 * a); " and "; (-b - sqrt ( d )) / (2 * a); "." 
  • end if 
0 0

Discussions

Post the discussion to improve the above solution.