Program Rumus ABC dengan C++ tanpa Class

Kali ini saya ingin membagikan bagaimana cara membuat program untuk rumus ABC dengan bahasa C++. Berikut adalah programnya:

#include <iostream>
#include <cmath>

int abc_pos(int a = 0, int b = 0, int c = 0) {
return (-b + (pow(b,2) – (4 * a * c))) / (2 * a);
}

int abc_neg(int a = 0, int b = 0, int c = 0) {
return (-b – (pow(b,2) – (4 * a * c))) / (2 * a);
}

int main() {
int x, y, z;

std::cout << “A = “; std::cin >> x;
std::cout << “B = “; std::cin >> y;
std::cout << “C = “; std::cin >> z;

std::cout << “x1 = ” << abc_pos(x,y,z) << std::endl;
std::cout << “x2 = ” << abc_neg(x,y,z) << std::endl;

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s