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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM