本题要求编写程序,计算两个二维平面向量的和向量。
输入格式:
输入在一行中按照“x1 y1 x2 y2”的格式给出两个二维平面向量v1=(x1,y1)和v2=(x2,y2)的分量。
输出格式:
在一行中按照(x, y)
的格式输出和向量,坐标输出小数点后一位(注意不能输出−0.0)。
输入样例:
3.5 -2.7 -13.9 8.7
输出样例:
(-10.4, 6.0)
// Date:2020/3/24
// Author:xiezhg5
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
double a,b,c,d;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
printf("(%.1lf, %.1lf)\n",a+c,b+d);
return 0;
}
// Date:2020/3/24
// Author:xiezhg5
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
double a,b,c,d;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
double x,y;
x=a+c;
y=b+d;
//题目的限定条件
if(fabs(x)<0.05)
x=0.0;
if(fabs(y)<0.05)
y=0.0;
printf("(%.1lf, %.1lf)\n",x,y);
return 0;
}