本题要求编写程序,计算两个二维平面向量的和向量。
输入格式:
输入在一行中按照“x1 y1 x2 y2”的格式给出两个二维平面向量V1=(x1, y1)和V2=(x2, y2)的分量。
输出格式:
在一行中按照“(x, y)”的格式输出和向量,坐标输出小数点后1位(注意不能输出-0.0)。
输入样例:
3.5 -2.7 -13.9 8.7
输出样例:
(-10.4, 6.0)
主要注意四舍五入即可AC,不是很麻烦。
#include <iostream>
using namespace::std;
struct Vector
{
double x;
double y;
};
void friter(double &x)
{
if (x>0) {
x=(double)((int)((x+0.05)*10))/10;
}
else
{
x=(double)((int)((x-0.05)*10))/10;
}
}
int main(int argc, const char * argv[])
{
Vector v1,v2,v3;
scanf("%lf %lf %lf %lf",&v1.x,&v1.y,&v2.x,&v2.y);
v3.x=v1.x+v2.x;
v3.y=v1.y+v2.y;
friter(v3.x);
friter(v3.y);
printf("(%.1lf, %.1lf)\n",v3.x,v3.y);
return 0;
}