Thursday, July 9, 2020

C Program to find the Roots of a Quadratic Equation

C Program to find the Roots of a Quadratic Equation How to write C Program to find the Roots of a Quadratic Equation? Back Home Categories Online Courses Mock Interviews Webinars NEW Community Write for Us Categories Artificial Intelligence AI vs Machine Learning vs Deep LearningMachine Learning AlgorithmsArtificial Intelligence TutorialWhat is Deep LearningDeep Learning TutorialInstall TensorFlowDeep Learning with PythonBackpropagationTensorFlow TutorialConvolutional Neural Network TutorialVIEW ALL BI and Visualization What is TableauTableau TutorialTableau Interview QuestionsWhat is InformaticaInformatica Interview QuestionsPower BI TutorialPower BI Interview QuestionsOLTP vs OLAPQlikView TutorialAdvanced Excel Formulas TutorialVIEW ALL Big Data What is HadoopHadoop ArchitectureHadoop TutorialHadoop Interview QuestionsHadoop EcosystemData Science vs Big Data vs Data AnalyticsWhat is Big DataMapReduce TutorialPig TutorialSpark TutorialSpark Interview QuestionsBig Data TutorialHive TutorialVIEW ALL Blockchain Blockchain TutorialWhat is BlockchainHyperledger FabricWhat Is EthereumEthereum TutorialB lockchain ApplicationsSolidity TutorialBlockchain ProgrammingHow Blockchain WorksVIEW ALL Cloud Computing What is AWSAWS TutorialAWS CertificationAzure Interview QuestionsAzure TutorialWhat Is Cloud ComputingWhat Is SalesforceIoT TutorialSalesforce TutorialSalesforce Interview QuestionsVIEW ALL Cyber Security Cloud SecurityWhat is CryptographyNmap TutorialSQL Injection AttacksHow To Install Kali LinuxHow to become an Ethical Hacker?Footprinting in Ethical HackingNetwork Scanning for Ethical HackingARP SpoofingApplication SecurityVIEW ALL Data Science Python Pandas TutorialWhat is Machine LearningMachine Learning TutorialMachine Learning ProjectsMachine Learning Interview QuestionsWhat Is Data ScienceSAS TutorialR TutorialData Science ProjectsHow to become a data scientistData Science Interview QuestionsData Scientist SalaryVIEW ALL Data Warehousing and ETL What is Data WarehouseDimension Table in Data WarehousingData Warehousing Interview QuestionsData warehouse architectureTalend T utorialTalend ETL ToolTalend Interview QuestionsFact Table and its TypesInformatica TransformationsInformatica TutorialVIEW ALL Databases What is MySQLMySQL Data TypesSQL JoinsSQL Data TypesWhat is MongoDBMongoDB Interview QuestionsMySQL TutorialSQL Interview QuestionsSQL CommandsMySQL Interview QuestionsVIEW ALL DevOps What is DevOpsDevOps vs AgileDevOps ToolsDevOps TutorialHow To Become A DevOps EngineerDevOps Interview QuestionsWhat Is DockerDocker TutorialDocker Interview QuestionsWhat Is ChefWhat Is KubernetesKubernetes TutorialVIEW ALL Front End Web Development What is JavaScript â€" All You Need To Know About JavaScriptJavaScript TutorialJavaScript Interview QuestionsJavaScript FrameworksAngular TutorialAngular Interview QuestionsWhat is REST API?React TutorialReact vs AngularjQuery TutorialNode TutorialReact Interview QuestionsVIEW ALL Mobile Development Android TutorialAndroid Interview QuestionsAndroid ArchitectureAndroid SQLite DatabaseProgramming aria-current=page>Uncat egorizedHow To Write C Program To Find... AWS Global Infrastructure C Programming Tutorial: The Basics you Need to Master C Everything You Need To Know About Basic Structure of a C Program How to Compile C Program in Command Prompt? How to Implement Linear Search in C? How to write C Program to find the Roots of a Quadratic Equation? Everything You Need To Know About Sorting Algorithms In C Fibonacci Series In C : A Quick Start To C Programming How To Reverse Number In C? How To Implement Armstrong Number in C? How To Carry Out Swapping of Two Numbers in C? C Program To Find LCM Of Two Numbers Leap Year Program in C Switch Case In C: Everything You Need To Know Everything You Need To Know About Pointers In C How To Implement Selection Sort in C? How To Write A C Program For Deletion And Insertion? How To Implement Heap Sort In C? How To Implement Bubble Sort In C? Binary Search In C: Everything You Need To Know Binary Search Introduction to C P rogramming-Algorithms What is Objective-C: Why Should You Learn It? How To Implement Static Variable In C? How To Implement Queue in C? How To Implement Circular Queue in C? What is Embedded C programming and how is it different? How to write C Program to find the Roots of a Quadratic Equation? Last updated on May 07,2020 8K Views Shubham Shah Bookmark How to write C Program to find the Roots of a Quadratic Equation? Calculating the roots of a quadratic equation is something that we have learnt in childhood. However, the complexity of quadratic equations increased with time. The methods to deal with this problem have also evolved. In this article, we would take a look a way to write a C program to find the roots of a quadratic equation.Following are the pointers to be covered in this article:What is a quadratic equation?Types of rootsUnderstanding the AlgorithmC program to find the roots of a Quadratic EquationLets begin.What is a Quadratic Equation?Before diving in to the coding part of this post, lets first understand what exactly is a quadratic equation? This section will give you a good understanding of quadratic equations which will help in understanding the algorithm. So, lets get back to the solution. An equation of degree 2 is known as a quadratic equation. If youre not familiar with the term degree, it is an order of an equation and its value is equal to the largest exponent present in an equation.DegreeEquation1Linear2Quadratic3CubicStandard FormLets see what is the standard form of a quadratic equation, which will help you in identifying them quickly.ax2 + bx + c = 0 is the standard form of a quadratic equation where the values of variables a, b, c is already known. The value of x is unknown and a not equal to 0.When you plot a quadratic equation on a graph, youll get a curve (parabola). The points at which this equation cuts the axis are its roots. Generally, there are 2 roots of a quadratic equation. Lets discuss the details of roo ts of a quadratic equation.Types of RootsThere are a few different ways to find the roots of a given quadratic equation. Such as, factoring the given quadratic equation, using the complete square formula and the last method involves using the quadratic formula to find the roots. I will stick to the last method as it has fewer drawbacks compared to the other methods.Lets consider our quadratic equation is in standard form ax2 + bx + c = 0, then the formula we can use is Now, lets talk about roots. Basically, the term inside the square-root (b2 4ac) in the numerator is also known as the discriminant. It can tell you more about the nature of the roots of the quadratic equation. Lets have a lookIf the value of the discriminant is Positive, that means we have 2 roots which are real in nature.If its value is negative, you have a pair of roots which are Complex in nature (eg- 5i, 8i).If it is 0, you get 2 roots having equal value and real in nature.Now that you have a deep understanding o f quadratic equations and their roots, we are good to start with the algorithm and it actually feels amazing when youll implement what youve learned in a real-world problem.Understanding the AlgorithmStep by step lets understand how we can write a program that can be used to find the roots of a quadratic equation.First, we will ask the user for the values of a, b, and c to form the quadratic equation.Once you have the values, you need to check if the value of a, entered is not 0. If its 0 our x2 term will be 0 and our equation wont be quadratic anymore.Now, you have a valid quadratic equation so you can calculate its discriminant value.After getting the discriminant value, you can check for the 3 conditions discussed above to know the nature of the roots.After knowing the nature, you can calculate its roots.Lets now look into the C program to find the roots of a quadratic equation.C program to find the roots of a Quadratic Equation#includestdio.h #includemath.h #includeconio.h #includestdlib.h /*Function to know the nature of roots and calculate the roots of given quadratic equation*/ void RootsofQuadratic(int a, int b, int c) { if (a == 0) /*Checking for value of a*/ { printf(The value of a cannot be 0); return; } int d = b*b - 4*a*c; double SquarerootDescriminant = sqrt(abs(d)); if (d 0) { printf(The Roots are Real in Nature n); printf(%fn%f,(double)(-b + SquarerootDescriminant)/(2*a) , (double)(-b - SquarerootDescriminant)/(2*a)); } else if (d == 0) { printf(The roots are equal and Real in Nature n); printf(%f,-(double)b / (2*a)); } else // d 0 { printf(The Roots are Complex in Nature n); printf(%f + i%fn%f - i%f, -(double)b / (2*a),SquarerootDescriminant ,-(double)b / (2*a), SquarerootDescriminant); } } int main() { int a; int b; int c; printf(For a quadratic equation of form ax2 + bx + c = 0 enter values of a, b, cn); scanf(%d%d%d, a, b, c); /*Asking for input*/ RootsofQuadratic(a, b, c); return 0; }Output:We received 2 complex roots for the values entered. Next time if you have a complex quadratic equation to solve, this program will definitely save you some time.Thats all for this article. I hope you have understood the concept and the C program to find the roots of a quadratic equation.If you come across any questions, feel free to ask all your questions in the comments section of quadratic equation in C and our team will be glad to answer.Recommended blogs for you Face Off: MongoDB Vs HBase Vs Cassandra Read Article NDTV Interview with Edureka’s Customers Team about its Learning Methodology Read Article How To Implement Getline In C++? Read Article SAFe Agile Certification Exam Requirements: Everything You Need to Know Read Article Software Testing Tutorial Know How to Perform Testing Read Article Edureka Success Story Mainframe Engineer to Big Data Analyst Read Article Big Data Engineer Skills: Skills Required To Become A Big Data Engineer Read Article 12 Tips to Hand le your First Campus Interview with a Software Company Read Article Vol. XXIV â€" Edureka Career Watch â€" Jan 2020 Read Article How To Implement Armstrong Number in C? Read Article Stack in Python: How, why and where? Read Article Golang Tutorial Learn Golang by Examples Read Article 8 Reasons why AngularJS should be used for development Read Article 7 Reasons to Choose Edureka Online Courses Read Article Everything You Need To Know About Functions in C? Read Article Vol. VI â€" Edureka Career Watch â€" 16th Feb. 2019 Read Article A Step-by-Step Guide On Automation Anywhere Installation Read Article Your Guide to the Top 10 IT Certifications for 2020 Read Article A Deconstruction of the Appium Architecture Read Article What is TOGAF ®: A Complete Overview Read Article Comments 0 Comments Trending Courses Python Certification Training for Data Scienc ...66k Enrolled LearnersWeekend/WeekdayLive Class Reviews 5 (26200)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.