From GibaĹ‚ka, 9 Months ago, written in C++.
Embed
Hits: 118 1.         std::cout << "y = ";
2.         if (a != 0) // if a is equal 0, we don't want to write ax^2, cuz its equal  0
3.         {
4.                 if (a != 1 && a != -1) // if a isn't equal -1 or 1, we write it
5.                         std::cout << a;
6.                 if (a == -1) // and if it's equal -1, we write '-'
7.                         std::cout << "-";
8.
9.                 std::cout << "x^2"; // and then we're writting x^2, cuz it's always anyway
10.         }
11.         if (b > 0 && a != 0) // if b is greater than 0 and a wasn't equal 0
12.                 //(cuz if was, we wouldn't wrote it and we don't want to write '+' after nothing)
13.                 std::cout << " + ";
14.         if(b!=0) // if b isn't equal 0, we write 'bx', cuz if is, we don't want to write it cuz it's equal 0
15.                 std::cout << b << "x";
16.         if (c > 0 && ( b != 0 || a != 0) ) // same case as previous, but it's checking not only for 'b' but for 'a' too
17.                 std::cout << " + ";
18.         if(c!=0) // and like with 'b', we're checking if 'c' isn't equal 0, cuz we don't want to write 0 if not needed
19.                 std::cout << c;
20.
21.         if (a == 0 && b == 0 && c == 0) // if all of 3 variables are equal 0, we're just writing 0
22.                 std::cout << "0";
23.
24.         std::cout << "\n";