Question

create a c language program that utilizes a static variable to calculate the zeroes of a...

create a c language program that utilizes a static variable to calculate the zeroes of a quadratic equation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <stdio.h>
#include <math.h>
int main()
{
   //Zeros of the equation: points at which given curve touches the x-axis are called zeros of that equation.
static int a, b, c, discriminant; //declaring static variable which represents coefficients of equation
static double root1, root2; //declaring static double root variables
printf("Enter a, b and c in a*x^2 + b*x + c = 0:\n");
scanf("%d%d%d", &a, &b, &c); //input the coefficients

discriminant = b*b - 4*a*c; //calculating the descriminent
printf("Zeros of the exuation %dx^2+%dx+%d=0 are:\n",a,b,c);
if (discriminant < 0) { //deciding roots based on descriminent
printf("(%.2lf + i%.2lf,0)\n", -b/(double)(2*a), sqrt(-discriminant)/(2*a)); //calculating the zeros of equation
printf("(%.2lf - i%.2lf,0)", -b/(double)(2*a), sqrt(-discriminant)/(2*a));
}
else { //here roots are real numbers
root1 = (-b + sqrt(discriminant))/(2*a); //calculating the zores of the equation
root2 = (-b - sqrt(discriminant))/(2*a);

printf("(%.2lf,0)\n", root1);
printf("(%.2lf,0)", root2);
}

return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
create a c language program that utilizes a static variable to calculate the zeroes of a...
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
  • C++ Visual Studios - Program - Vector - Simple Create a program that utilizes VECTOR for...

    C++ Visual Studios - Program - Vector - Simple Create a program that utilizes VECTOR for the following topic. Topic: Carl's Cab Stand needs a program to keep track of their daily clients. Your program shall allow the user to enter 10 names. You will then retrieve the names, one by one, from the data structure (using the appropriate method of retrieval for each data structure) and present them on-screen so that Carl knows who to service next. Include a...

  • Using C++ For this program you are going to create a class that helps to solve...

    Using C++ For this program you are going to create a class that helps to solve the quadratic equation. The equation has the following form: ax2 + bx + c = 0 The roots of the equation are: x1 = -b + sqrt(b2 - 4 * a * c) and x2 = -b - sqrt(b2 - 4 * a * c) The phrase in the parenthesis is called the discriminant. If the value of the discriminant is positive, the equation...

  • Answer should be in C programming language Write a program that will create an array of...

    Answer should be in C programming language Write a program that will create an array of 10 floating point numbers and take input 10 floats from keyboard. The program will print the position (index) of the maximum and minimum number among them

  • THE PROGRAMMING LANGUAGE IS C++ Part 1.Create a program that decides whether a given integer is...

    THE PROGRAMMING LANGUAGE IS C++ Part 1.Create a program that decides whether a given integer is prime or not. The program should at the end of its analysis print the number followed by prime or composite. Part 2.Make the program from part 1 print the prime factors of any composite number entered (an additional feature to Part 1). THE PROGRAMMING LANGUAGE IS C++

  • Write a Program in C language for: 1. Create a C program to read 7 integers...

    Write a Program in C language for: 1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...

  • program in assembiy language x86 In assembly language using float point Quadratic Formula Prompt the user...

    program in assembiy language x86 In assembly language using float point Quadratic Formula Prompt the user for coefficients a, b, and c of a polynomial in the form ax²+bx +C =0. Calculate and display the real roots of the polynomial using the quadratic formula. If any root is imaginary, display an appropriate message. Your result must be calculated in floating point whenever it applies, otherwise you will NOT get any credit.

  • In the following C program, indicate the variable type (global, local, or static local), the lifetime...

    In the following C program, indicate the variable type (global, local, or static local), the lifetime (when the program is run or when the function is called), and the memory allocation (from stack or from heap) for each variable (x, y, z, and w) defined in the program. int w; void fun (int x) { int y; static float z; ... } void main() { fun(w); }

  • CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic...

    CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic equation. Background: A quadratic equation can be generalized by equation below: f ( x )=ax2+ bx +c Closed form solutions can be found for the zeros of a quadratic function conveniently. That is the locations where the function is equal to zero can be found by the following equation: x=− b± √ b −4ac 2a Note that depending on the sign of the expression...

  • Hello. my assignment requires to create a program using the C language and that must contain...

    Hello. my assignment requires to create a program using the C language and that must contain the following: - Error Checking - Use of Functions - Menu system - Array Processing -No Global variables the theme of the program can be about anything but must contain the features mentioned above Thanks in advance

  • Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi. Write...

    Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi. Write the code in easy way means coding should of beginner level. Also use more and more comments in the code for better understanding. The code should complete and should able to run. Also provide output of the program.

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