100% prog to find and print roots of quadratic equation

//program to print roots of quadratic equation ax^2+bx+c=0;  (a!=0)
#include <stdio.h>

void main()
{
  float a,b,c,temp,root1,root2;
  printf("\n enter the coefficients of the polynomial ax^2+bx+c where a!=0: ");
   scanf("%f%f%f",&a,&b,&c);
   temp=b*b-4*a*c;
   if(temp>=0) //roots are real
   {
       root1=(-b+sqrt(temp))/(2*a);
       root2=(-b-sqrt(temp))/(2*a);
       printf("\n root1=%f   root2= %f",root1,root2);
   }
   else
   {
       printf("\n root1 = %f",-b/(2*a)); //only real part
       printf("+i %f",sqrt(temp)/(2*a));
       printf("\n root2 = %f",-b/(2*a)); //only real part
       printf("-i %f",sqrt(temp)/(2*a));
   }
 
}
ఔట్పుట్  తెరమీద   
enter the coefficients of the polynomial ax^2+bx+c where a!=0: 1  3  2
root1=-1.000000   root2= -2.000000

enter the coefficients of the polynomial ax^2+bx+c where a!=0: 1 1 1
root1 = -0.500000+i 0.866025
 root2 = -0.500000-i 0.866025

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

Useful books in telugu

ధన్యవాదములు.. కాస్త తెలుగు కూడా ఉపయోగించమ్మా.. Re: Assignment 1

Useful books from Ramakrishna mission (telugu & Hindi)