022. Write a program to calculate roots of a quadratic equations in C language

x=b^2-4ac
if x=0 -> only one root ,
if x>0 -> roots are distinct (–b+x)/2a & (–b-x)/2a
if x<0 -> roots are imaginary

#include<stdio.h>
#include<conio.h>
main()
{
 float x,r1,r2,a,b,c;
 clrscr();
 printf("Enter a,b,c...");
 scanf("%f%f%f",&a,&b,&c);
 x=b*b-4*a*c;
 r1=(-b+x)/2*a;
 r2=(-b-x)/2*a;
 if(x>0)
		printf("\nRoots are unequal...\n");
 else if(x<0)
		printf("\nRoots are imaginary...\n");
 else
		printf("\nRoots are same....\n");
 printf("R1 = %f",r1);
 printf("R2 = %f",r2);
 getch();
}

2 thoughts on “022. Write a program to calculate roots of a quadratic equations in C language

Leave a Reply

Your email address will not be published. Required fields are marked *