C program to find roots of a quadratic equation

/* write a C program to find and output all the roots of a    *  * quadratic equation, for non-zero coefficients. In case     *  * of err...


/* write a C program to find and output all the roots of a    *
 * quadratic equation, for non-zero coefficients. In case     *
 * of errors your program should report suitable error message*/

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

void main()
{
    float A, B, C, root1, root2;
    float realp, imagp, disc;

    clrscr();

    printf("Enter the values of A, B and C\n");
scanf("%f %f %f", &A,&B,&C);

/* If A = 0, it is not a quadratic equation */

if( A==0 || B==0 || C==0)
    {
printf("Error: Roots cannot be determined\n");
exit(1);
}
else
{
disc = B*B - 4.0*A*C;
if(disc < 0)
{
printf("Imaginary Roots\n");
realp = -B/(2.0*A) ;
imagp = sqrt(abs(disc))/(2.0*A);
printf("Root1 = %f  +i %f\n",realp, imagp);
printf("Root2 = %f  -i %f\n",realp, imagp);
}
else if(disc == 0)
{
printf("Roots are real and equal\n");
root1 = -B/(2.0*A);
root2 = root1;
printf("Root1 = %f  \n",root1);
printf("Root2 = %f  \n",root2);
}
else if(disc > 0 )
{
printf("Roots are real and distinct\n");
root1 =(-B+sqrt(disc))/(2.0*A);
root2 =(-B-sqrt(disc))/(2.0*A);
printf("Root1 = %f  \n",root1);
printf("Root2 = %f  \n",root2);
}
 }

 }   /* End of main() */

 /*---------------------------
 Output
 RUN 1
 Enter the values of A, B and C
 3 2 1
 Imaginary Roots
 Root1 = -0.333333  +i 0.471405
 Root2 = -0.333333  -i 0.471405

 RUN 2
 Enter the values of A, B and C
 1 2 1
 Roots are real and equal
 Root1 = -1.000000
 Root2 = -1.000000

 RUN 3
 Enter the values of A, B and C
 3 5 2
 Roots are real and distinct
 Root1 = -0.666667
 Root2 = -1.000000
 ---------------------------------*/

Related

C TUTORIAL 397776122566361604

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

Search Here

Popular query

Ads By Google

Get free Update

Enter your email address:

E-mail verification is must for complete subscription

Delivered by FeedBurner

RecentRecommendedComments

Recent

Patent Agent Examination 2025| Paper 2 (II) | Question no 3

A textile machine manufacturer invented a weaving machine with very high productivity as compared to state of the art machines. A patent application for the same was granted on 30/12/2024.What is...

Patent Agent Examination 2025| Paper 2 (II) | Question no 2

Mr. Hariharan is the owner of a small tech start-up company that has recently developed aninnovative tool for managing customer relationships. Mr. Hariharan has been working hard to gain traction...

Patent Agent Examination 2025| Paper 2 (II) | Question no 1

 Recently, the Patents (Amendment) Rules, 2024 has relaxed some burden on the applicant in terms of fulfilment of the requirements for filing information and undertaking regarding corresponding f...

The OnePlus Pad 2: A Comprehensive Review of the Latest Tablet Innovation

In the competitive landscape of tablets, the OnePlus Pad 2 emerges as a formidable contender, blending cutting-edge technology with sleek design to deliver a compelling user experience. Whether you're...

How to Keep Pond Water Clean Using Quick Lime and Potassium Permanganate

Maintaining a clean and healthy pond environment is crucial for the well-being of aquatic life. Two effective substances for achieving this are quick lime (calcium oxide) and potassium permanganate (K...

Comments

Urvi Blog:

Nice blog you are posting thanks for your post : BS System Solutions

Make Cash:

UPLOAD SAMPLE FILLED UP FORM OF NOTE SHEET.

Anonymous:

Best blog I received valuable thing it give me full information. thank for making this kind of blog.it help me a lot. for more this kind of information you can check my blog also the International Co...

mithu dowari:

please provide NOC from

Circle AFS on Google Plus!

Follow AFS Google+ page
 

Side Ads

DMCA protected
Information, images and the content on this blog is Copyright ©AFS2011-2018. Please do not copy Any content for commercial purpose else we have to take a legal action. Thanks !!

Total Pageviews

2821578

Recent

free counters
 

Connect Us

Speech by ReadSpeaker

item