习题9-3 平面向量加法 (15point(s)).c

本题要求编写程序,计算两个二维平面向量的和向量。

输入格式:

输入在一行中按照“x​1​​ y​1​​ x​2​​ y​2​​”的格式给出两个二维平面向量v​1​​=(x​1​​,y​1​​)和v​2​​=(x​2​​,y​2​​)的分量。

输出格式:

在一行中按照(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;
}

 

发布了131 篇原创文章 · 获赞 94 · 访问量 2964

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105079524