Write a C Program to Find the Roots of a Quadratic Equation by using if-else and else-if Statement

Quadratic Equation

Statement of C Program: This Program finds all the Roots of a Quadratic Equation, for non-zero cofficients:

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float A , B , C , root1 , root2;
float realp , imgp , disc;               
                                      /* realp stands for Real Part and imgp stands for Imaginary Part */
clrscr();
printf(" Enter the values of A , B and C\n");
scanf("%f%f%f" , &A , &B , &C);

if(A==0 || B==0 || C==0)
{
printf(" Error: Roots cannot be determined\n");
}

else
{
dis = (B * B) - (4 * A * C);
if(disc<0)
{
printf(" Imaginary Roots\n");
realp = -B/(2*A);
imagp = sqrt(abs(disc))/(2*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 * 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*A);
root2 = (-B - sqrt(disc))/(2*A);
printf(" Root1 = %f\n" , root1);
printf(" Root2 = %f\n" , root2);
}

}
}                                               /*  End of main()  */


Output1:
Enter the values of A , B and C
3 2 1
Imaginary roots
Root1 = -0.3333 + i0.471402
Root2 = -0.3333 - i0.471405


Output2:
Enter the values of A , B and C
1 2 1
Roots are real and equal
Root1 = -1.0000
Root2 = -1.0000


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

                 
                                                              That's All !
                                   

0 Response to "Write a C Program to Find the Roots of a Quadratic Equation by using if-else and else-if Statement"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag