0% found this document useful (0 votes)
9 views1 page

How To Write A C Program To Find The Roots of A Quadratic Equation

Uploaded by

bmk7tp267x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

How To Write A C Program To Find The Roots of A Quadratic Equation

Uploaded by

bmk7tp267x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Menu Categories Login

Java Search articles...

JSP

iOS
SQL HTML CSS Javascript Python
HTML

How to write a C program to


Android
find the roots of a quadratic
Python
equation?
CC Programming
Server Side Programming Programming

C++ Programming

C#

Problem
Applying the software development method to
solve any problem in C Language.

Solution

Find roots of a quadratic equation,

ax2+bx+c.

There will be 2 roots for given quadratic


equation.

Explore our latest online courses and learn


new skills at your own pace. Enroll and become
a certified expert to boost your career.

Analysis
Input − a,b,c values

Output − r1, r2 values

Procedure
−b+√b2−4ac
r1 = 2a

−b−√b2−4ac
r2 = 2a

Design (Algorithm)

Start

Read a, b, c values

Compute d = b2 4ac

if d > 0 then

r1 = b+ sqrt (d)/(2*a)

r2 = b sqrt(d)/(2*a)

Otherwise if d = 0 then

compute r1 = -b/2a, r2=-b/2a

print r1,r2 values

Otherwise if d < 0 then print roots are


imaginary

Stop

Implementation Code

# include<stdio.h>
# include<math.h>

int main () {
float a,b,c,r1,r2,d;

printf ("Enter the values of a b c: "


scanf (" %f %f %f", &a, &b, &c);

d= b*b - 4*a*c;

if (d>0) {
r1 = -b+sqrt (d) / (2*a);
r2 = -b-sqrt (d) / (2*a);
printf ("The real roots = %f %f",
}
else if (d==0) {
r1 = -b/(2*a);
r2 = -b/(2*a);
printf ("Roots are equal =%f %f",
}
else
printf("Roots are imaginary");

return 0;
}

Testing

Case 1:
Enter the values of a b c: 1 4 3
The real roots = -3.000000 -5.000000
Case 2:
Enter the values of a b c: 1 2 1
Roots are equal =-1.000000 -1.000000
Case 3:
Enter the values of a b c: 1 1 4
Roots are imaginary

Bhanu Priya

Updated on: 01-Sep-2023

130K+ Views

Related Articles
C++ Program to Find All Roots of a
Quadratic Equation

C program to find the Roots of Quadratic


equation

Java program to find the roots of a


quadratic equation

Haskell program to find all roots of a


quadratic equation

Kotlin Program to Find all Roots of a


Quadratic Equation

How to Find all Roots of a Quadratic


Equation in Golang?

How to identify the real roots of a


Quadratic Equation in Excel?

Finding roots of a quadratic equation –


JavaScript

Nature of Roots of Quadratic Equation

Program to find number of solutions in


Quadratic Equation in C++

Write all the values of k for which the


quadratic equation x2 + kx + 16 = 0 has
equal roots. Find the roots of the equation
so obtained.

Find the quadratic roots in the equation


4x2 − 3x + 7

If 1 is a root of the quadratic equation


3x2 + ax − 2 = 0 and the quadratic
equation a(x2 + 6x) − b = 0 has equal
roots, find the value of b.

If 2 is a root of the quadratic equation


3x2 + px − 8 = 0 and the quadratic
equation 4x2 − 2px + k = 0 has equal
roots, find the value of k.

Find the roots of the following quadratic



equation:x2 − 3√5 x + 10 = 0

Kickstart Your Career


Get certified by completing the course

Get Started

Print Page Previous Next

Advertisements

TOP TUTORIALS

Python Tutorial

Java Tutorial

C++ Tutorial

C Programming Tutorial

C# Tutorial

PHP Tutorial

R Tutorial

HTML Tutorial

CSS Tutorial

JavaScript Tutorial

SQL Tutorial

TRENDING TECHNOLOGIES

Cloud Computing Tutorial

Amazon Web Services Tutorial

Microsoft Azure Tutorial

Git Tutorial

Ethical Hacking Tutorial

Docker Tutorial

Kubernetes Tutorial

DSA Tutorial

Spring Boot Tutorial

SDLC Tutorial

Unix Tutorial

CERTIFICATIONS

Business Analytics Certification

Java & Spring Boot Advanced Certification

Data Science Advanced Certification

Cloud Computing And DevOps

Advanced Certification In Business Analytics

Artificial Intelligence And Machine Learning

DevOps Certification

Game Development Certification

Front-End Developer Certification

AWS Certification Training

Python Programming Certification

COMPILERS & EDITORS

Online Java Compiler

Online Python Compiler

Online Go Compiler

Online C Compiler

Online C++ Compiler

Online C# Compiler

Online PHP Compiler

Online MATLAB Compiler

Online Bash Compiler

Online SQL Compiler

Online Html Editor

ABOUT US | OUR TEAM | CAREERS | JOBS |


CONTACT US | TERMS OF USE | PRIVACY POLICY |
REFUND POLICY | COOKIES POLICY | FAQ'S

Tutorials Point is a leading Ed Tech company striving


to provide the best learning material on technical
and non-technical subjects.

© Copyright 2024. All Rights Reserved.

Sign in with Google

Use your Google Account

You might also like