Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Homework 1 topic is the creation of a C language program to calculate and present the two solutions of the following quadratic equation: a

The Homework 1 topic is the creation of a C language program to calculate and present the two
solutions of the following quadratic equation:
ax2+bx+c=0, where the coefficients a,b,c are real numbers with a0
It is a fact that the solutions are either 2 real numbers or 2 complex conjugate numbers,
depending on the value of the discriminant, D=b2-4ac.
Specifically,
If the discriminant satisfies D0, then the 2 quadratic roots are real numbers, given
by,
xr1=-b+D22a
xr2=-b-D22a
else, the 2 roots are complex conjugate numbers, given by,
xc1= Real +j Imag =(-b2a)+j(-D22a)
xc2= Real -j Imag =(-b2a)-j(-D22a)
A C language code is provided but it's incomplete. There are gaps to be completed in order to
run correctly and to provide the correct answers. The Homework assignment consists of 4 tasks
as detailed below:
Task 1(10 points): Provide the pseudocode that is relevant to this programming task
(refer to Fig. 1).
Task 2(10 points): Complete the flowchart that is relevant to this programming task
(refer to Fig. 1).
Task 3(10 points): Complete the gaps in the provided C code using the correct syntax
and debug your code so that it runs correctly.
Task 4(10 points): Test your code using the provided test cases.|
============================
#include stdio.h>
#include math.h>
/* This program finds the solutions of the quadratic equation ax2+b*x+c=0*/
int main()
{
/* Define and initialize the variables*/
float D, real_root1, real_root2, real_part, imag_part;
/* Input the coefficients of the equation and ensure that a is not equal to zero*/
while (){
printf("Specify the coefficients of the quadratic a {:x2+bx+c,
");
printf("The value of the a coefficient must be non-zero");
}
/* Calculate the discriminant value*/
D =
/* Write an if/else statement to check if the roots are real or complex numbers*/
if ()
{
real_root1=-b+sqrt(D)2*a;
real_root2=
printf("The real roots of the ",);
printf("",);
}
else
{
real_part =
imag_part =sqrt(-D)/(2*a);
printf("The complex roots of the quadratic%.2fx2+%.2fx+%.2f are
",a,b,c;
printf("x1=%.4f+j%.4f,x2=%.4f-j%.4f", real_part,imag_part,real_part,imag_part):
}
return 0 ;
}
=================
1) In line 15 of the code, write an appropriate command to define the variables of the
coefficients ab and c as float variables. (1 point)
2)In line 17, initialize the variable t to be equal to zero. (1 point)
3)In line 20, specify the correct condition for the while loop. If the condition is satisfied then the loop continues to run. (1 point)
4) In line 23, write a command to receive numerical values and assign them to the
coefficients ab and point)
5) In line 26, complete the numerical expression for the discriminant value Q1 point)
6) In line 29, specify the condition of the if/else statement so that the first part of the if/else statement produces the real roots and the second part of the if/else statement produces the complex roots. (1 point)
7) In line 32, write the numerical expression so that the code can calculate the second real root. (1 point)
8) In lines 33,34, write appropriate printf commands to obtain the following output when the code runs correctly with input values ab c 2-5
[ The real roots of the quadratic 1.00x2+-5.00x+6.00 are
x1=3.0000,x2=2.0000]
9) In line 38, write the correct numerical expression for the real part of the complex roots.
(1 point)
============
Output:
If you enter the values ab c the should produce the following result,
[ The real roots of the quadratic 1.00x2+-2.00x+-8.00 are
x1=4.0000,x2=-2.0000]
If you enter the values abc the code should produce the following result,
]
Submit your completed code.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions