zoukankan      html  css  js  c++  java
  • 11-0. 平面向量加法(10)

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

    输入格式:

    输入在一行中按照“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)
    
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 struct data{
     5     double x[2];
     6     double y[2];
     7 }dat;
     8 
     9 struct data *input();
    10 
    11 int main()
    12 {
    13     input(&dat);
    14 
    15     double dat_x = dat.x[0] + dat.x[1];
    16     double dat_y = dat.y[0] + dat.y[1];
    17     if(dat_x > -0.05 && dat_x < 0.05) {          //四舍五入 
    18         dat_x = 0.0; 
    19     }
    20     if(dat_y > -0.05 && dat_y < 0.05) {
    21         dat_y = 0.0;
    22     } 
    23     printf("(%.1lf, %.1lf)", dat_x, dat_y);
    24     
    25     return 0;
    26 } 
    27 
    28 struct data *input(struct data *da)
    29 {
    30     scanf("%lf %lf %lf %lf", &(da->x[0]), &(da->y[0]), &(da->x[1]), &(da->y[1]));
    31     
    32     return da;
    33 }
  • 相关阅读:
    Eclipse
    svn 常用
    spidermonkey编译
    float format 显示
    点击6次修改服务器地址
    UITextField字数限制
    UINavigationController
    运行时runtime
    IOS 技术与面试
    Cocos2dx笔记
  • 原文地址:https://www.cnblogs.com/aexin/p/3902627.html
Copyright © 2011-2022 走看看