HOME BZU Mail Box Online Games Radio and TV Live Cricket Score All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Institute of Computing Bachelor of Science in Information Technology BsIT 2nd Semester Object Oriented Programming


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 08-03-2011, 11:58 PM
bonfire's Avatar
M.Arsalan Qureshi

 

Join Date: Oct 2008
Location: Garden Town, Multan Cantt
Posts: 616
Program / Discipline: BSTS
Class Roll Number: 09-31
bonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond repute
Default Program to find the roots of a quadratic equation


Program to find the roots of a quadratic equation


#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{
clrscr();
float a,b,c,d,root1,root2;
cout << "Enter the 3 coefficients a, b, c : " << endl;
cin>>a>>b>>c;
if(!a){
if(!b)
cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" << "\n";
else
{
d=-c/b;
cout << "The solution of the linear equation is : " << d << endl;
}
}
else
{
d=b*b-4*a*c;
if(d>0)
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout << "The first root = " << root1 << endl;
cout << "The second root = " << root2 << endl;
}
getch();
return 0;
}
This program takes in the values of the three coefficients a, b, and c as a screen input from the user.
It then determines the roots of the quadratic equation using the formula ax^2 + bx + c = 0.
The two roots are then outputted using the 'cout' command.

Sample Input 4 4 -3
Sample Output
The first root = 0.5
The second root = -1.5
__________________

Reply With Quote
Reply

Tags
equation, find, program, quadratic, roots


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Program to find number in an array JuNaiDiQbaL Object Oriented Programming 0 06-05-2011 10:32 PM
Program to find the sum of either of the diagonals of a 4 x 4 matrix bonfire Object Oriented Programming 0 09-03-2011 12:26 AM
Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals bonfire Object Oriented Programming 0 09-03-2011 12:01 AM
Program to enter an integer and find out if it is even or odd bonfire Object Oriented Programming 0 01-03-2011 03:08 PM
Program to find the Sum of all elements in an Array (By Sheraz) .BZU. Visual Programming 0 15-12-2009 11:00 PM

Best view in Firefox
Almuslimeen.info | Cloud Computing | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 09:35 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.