Question

Recursive Quadratic Design 2: draw a picture of the data and give the formula, and type...

Recursive Quadratic Design 2: draw a picture of the data and give the formula, and type the algorithm for this program   

Due: ___________________   

RECURSIVE QUADRATIC - Program 2(100 points) CS1311

Write a C program that finds the value of a specific quadratic function

f(x) = ax^2 + bx + c

where you pick a, b and c (before you program) to be non-zero integers.

Use the function we worked with in class!  Do not put a, b or c in the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include<math.h>

int quadratic(double a, double b, double c, double *solution1, double *solution2){
   double d = b * b - 4.0 * a * c;
    if (d < 0)
    {
       *solution1 = 0;
       *solution2 = 0;
        return 0;
    }
    else if (d == 0)
    {
      *solution1 = -b / (2.0 * a);
        *solution2 = -b / (2.0 * a);
        return 1;
   }
    else
    {
        *solution1 =(-b + sqrt(d)) / (2.0 * a);
        *solution2 =(-b - sqrt(d)) / (2.0 * a);
        return 1;
    }
}

int main(int argc, char *argv[]) {
   
   double a, b, c, root1, root2, d;
 
   printf("Enter a: ");
   scanf("%lf",&a);
    printf("Enter b: ");
   scanf("%lf",&b);
    printf("Enter c: ");
   scanf("%lf",&c);
    
       d = b * b - 4.0 * a * c;
        if (d < 0)
        {
           printf("Complex conjugates\n");
        }
        else if (d == 0)
        {
           printf("Repeated real roots\n");
            root1 = -b / (2.0 * a);
            root2 = root1;
            printf("Root1 = %lf\n", root1);
            printf("Root2 = %lf\n", root2);
        }
        else if (d > 0 )
        {
           printf("Real distinct roots\n");
            root1 =(-b + sqrt(d)) / (2.0 * a);
            root2 =(-b - sqrt(d)) / (2.0 * a);
            printf("Root1 = %lf\n", root1);
            printf("Root2 = %lf\n", root2);
        }
    
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Recursive Quadratic Design 2: draw a picture of the data and give the formula, and type...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and...

    Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and finds the sum of the primes in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C++, ..... You do not need to write a function to determine whether a number is prime. Assume it is part of your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 17 (because 2 +...

  • 10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate...

    10) p. 53, problem 2.4.7. Write a Python program that uses the Quadratic Formula to calculate the real solutions to an equation in the form x 2 +bx+c=0 . Prompt the user to enter values for a, b, and c, then display the solutions. For the purposes of this assignment, you may assume that every equation will have two distinct, real solutions. Put your program in the Homework 1 folder on your K: drive. Here is a sample run of...

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • Complete 1. Create a function to solve the Quadratic Formula as know as ax +bx+cwit solution...

    Complete 1. Create a function to solve the Quadratic Formula as know as ax +bx+cwit solution is 2a The function must have only 3 reference parameters which are the coefficient of the quadratic equation a, b and c, at the end the function must return the real value of x. If a-0, or there is a negative root square obtained, the function must sent a message error to the user The coefficient of it can't be equal zero" or "Negative...

  • In Python. The two roots of a quadratic equation ax^2 + bx + c = 0...

    In Python. The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r2 = (-b - sqrt(b^2 - 4ac) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...

  • please answer this question with python. Write a program to solve the quadratic equation ax^2 +...

    please answer this question with python. Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...

  • CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation...

    CSC 211 - Lab-2 Write a C++ program to find the roots of a quadratic equation ax +bx+c=0. The roots are given by the formula, x=-b I56²-4ac 2a x = -b+ √b²-4ac 2. x2 = -b-√6²-4ac 2a Instructions: 1. Type, compile, and run the program in an online C++ compiler. 2. Open a word document and copy the following items onto it: a. The source code b. Screenshot of your program's result 3. Save the word document as lastnameFirstname_Lab2.docx (for...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • c++ language TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program...

    c++ language TECH 1211 Computer Programming Name Test 2 Hands-On-Program B Spring 2020 Write a program that uses the quadratic formula to solve quadratic equations. Background Given the format for a quadratic equations: aX? +BX+C =0 The coefficient of the X term is the number a. The coefficient of the X term is the number b. The value of c is any non-zero constant. These values can be positive, negative or zero. You can find the solution to this equation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT