۱۳۹۶ مهر ۸, شنبه

c++ - Is it possible to show positive/negative sign without std::showpos, loop or other library?

[ad_1]



I wonder if it's possible to show positive/negative sign without std::showpos, loop or other library?



#include <iostream>

using std::cout;
using std::cin;

int main()

int x1, x2, y1, y2, x, y, z;

cout << "Linear equation system of two variablesnX1 : ";
cin >> x1;
cout << "X2 : ";
cin >> x2;
cout << "Y1 : ";
cin >> y1;
cout << "Y2 : ";
cin >> y2;

y = x2 - x1;
x = (y2 - y1) * -1;
z = (y * y1) + (x * x1);

cout << "Result : " << y << "y" << x << "x = " << z;
return 0;



I know use std::showpos or loop such as (x>0)?cout<<"+"<<y:cout<<""<<y; are easier, but i wonder if's possible to show "+" sign without these solution?




[ad_2]

لینک منبع