Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update quadratic.cpp #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions 2-variables/quadratic-formula/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#include <iostream>
// Quadratic formula
#include <iostream>
#include <cmath>

int main() {
int main(){
// 1. declare variable a,b,c
double a,b,c;

double a, b, c;
double root1, root2;

std::cout << "Enter a: ";
//2,3 Input a,b,c
std::cout << "Enter a : ";
std::cin >> a;

std::cout << "Enter b: ";
std::cout << "Enter b : ";
std::cin >> b;

std::cout << "Enter c: ";
std::cout << "Enter c : ";
std::cin >> c;

// 4. declare two variable root1 and root2
double root1, root2;

// 5. formula of root1
root1 = (-b + std::sqrt(b*b - 4*a*c)) / (2*a);
root2 = (-b - std::sqrt(b*b - 4*a*c)) / (2*a);

std::cout << "Root 1 is " << root1 << "\n";
std::cout << "Root 2 is " << root2 << "\n";

return 0;

}