您的位置:首页 > 其它

结构-03. 平面向量加法(10)

2015-02-16 00:10 197 查看
本题要求编写程序,计算两个二维平面向量的和向量。

输入格式:

输入在一行中按照“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)


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>

using namespace::std;

int main(){
char s[100];
gets(s);
//划分

double a,b,c,d;
sscanf(s,"%lf %lf %lf %lf",&a,&b,&c,&d);
double m=a+c,n=b+d;
if(m>-0.05&&m<=0)m=0.0;
if(n>-0.05&&n<=0)n=0.0;
printf("(%.1f, %.1f)",m,n);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: