当前位置:网站首页>Electronic Society C language level 1 31. Calculate line segment length
Electronic Society C language level 1 31. Calculate line segment length
2022-06-26 22:46:00 【dllglvzhenfeng】
Electronics Association C Language 1 level 31 、 Calculate the line length
OpenJudge - 16: Calculate the line length
C++ Method 1 :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length
http://noi.openjudge.cn/ch0103/16/
The coordinates of the two endpoints of a given line segment A(Xa,Ya),B(Xb,Yb), Find line segment AB The length of .
There are two lines of input .
The first line is two real numbers Xa,Ya, namely A Coordinates of .
The second line is two real numbers Xb,Yb, namely B Coordinates of .
The absolute value of all real numbers in the input does not exceed 10000.
Output
A real number , That's line segments AB The length of , Keep it after the decimal point 3 position .
The sample input
1 1
2 2
Sample output
1.414
The coordinates of the two endpoints of a given line segment A(Xa,Ya),B(Xb,Yb), Find line segment AB The length of .
http://noi.openjudge.cn/ch0103/16/
*/
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double xa,xb,ya,yb,len;
cin>>xa>>ya;
cin>>xb>>yb;
len=sqrt( pow(xa-xb,2)+pow(ya-yb,2) );
//len=sqrt(pow(2,xa-xb) +pow(2,ya-yb));
//sqrt( ) Square root function pow( ) power function
printf("%0.3f",len);
return 0;
}C++ Method 2 :
/* Electronics Association C Language 1 level 31 、 Calculate the line length Method 2 http://noi.openjudge.cn/ch0103/16/ */ #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double Xa, Ya, Xb, Yb; cin >> Xa >> Ya >> Xb >> Yb; double ans; //ans=sqrt(pow((Xa-Xb),2)+pow((Ya-Yb),2)); ans=sqrt( (Xa-Xb)*(Xa-Xb) + (Ya-Yb)*(Ya-Yb) ); cout << fixed << setprecision(3) <<ans ; return 0; }
C++ Method 3 :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method 3
http://noi.openjudge.cn/ch0103/16/
*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
double a,b,c,d;
cin>>a>>b;
cin>>c>>d;
printf("%.3f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
//printf("%.3f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
return 0;
}C++ Method four :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method four
http://noi.openjudge.cn/ch0103/16/
*/
#include <math.h>
#include <stdlib.h>
int main()
{
double Xa,Ya,Xb,Yb;
double l;
scanf("%lf%lf%lf%lf",&Xa,&Ya,&Xb,&Yb);
l=sqrt((Xb-Xa)*(Xb-Xa)+(Yb-Ya)*(Yb-Ya));
printf("%.3lf\n",l);
system("pause");
return 0;
}C++ Method five :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method five
http://noi.openjudge.cn/ch0103/16/
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float xa,ya,xb,yb;
scanf("%f%f%f%f",&xa,&ya,&xb,&yb);
printf("%.3f\n",sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)));
system("pause");
return 0;
}python3 Code :
"""
1.3 Arithmetic expression and sequential execution of programming basis 16 Calculate the line length
http://noi.openjudge.cn/ch0103/16/
https://blog.csdn.net/weixin_45852964/article/details/103090884
"""
import math
xa,ya=map(float,input().split())
xb,yb=map(float,input().split())
l=math.sqrt((yb-ya)*(yb-ya)+(xb-xa)*(xb-xa))
print("%.3f"%l)Electronics Association Youth software programming level test C Language over the years
Electronics Association C Language Real and simulated questions
Electronics Association C Language 1 level 5 、 Judge whether it can be 3 ,5 ,7 to be divisible by
Electronics Association C Language 1 level 6 、 Cycling and walking
Electronics Association C Language 1 level 7 、 Draw a rectangular
Electronics Association C Language 1 level 18 、 Calculate postage
Electronics Association C Language 1 level 19 、 Find the sum and mean of integers
Electronics Association C Language 1 level 21 、 The problem of logical judgment Enter three numbers a,b,c, The largest output
Electronics Association C Language 1 level 23 、 Judge the average leap year
Electronics Association C Language 1 level 24 、 Find the greatest common divisor
Electronics Association C Language 1 level 28 、 Character diamond
Electronics Association C Language 1 level 29 、 Align output
Electronics Association C Language 1 level 29 、 Align output
Electronics Association C Language 1 level 29 、 Align output _dllglvzhenfeng The blog of -CSDN Blog
Electronic Society junior programming grade test
边栏推荐
- UnityEditor编辑器扩展-表格功能
- [cloud native topic -51]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - database middleware redis microservice deployment process
- 电子协会 C语言 1级 31 、 计算线段长度
- 这个算BUG吗?乱填的字母是否可以关闭
- DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
- Unity3D插件 AnyPortrait 2D骨骼動畫制作
- 在哪个平台买股票开户最安全?求分享
- [bug feedback] the problem of message sending time of webim online chat system
- [Old Wei makes machines] issue 090: keyboard? host? Full function keyboard host!
- Why don't I recommend going to sap training institution for training?
猜你喜欢

Using C to operate SQLSERVER database through SQL statement tutorial

在Flutter中解析复杂的JSON

Configuring assimp Library in QT environment (MinGW compiler)

YOLOv6:又快又准的目标检测框架开源啦

开放世界机甲游戏-Phantom Galaxies

360 mobile assistant is the first to access the app signature service system to help distribute privacy and security

leetcode:710. 黑名单中的随机数【映射思维】

Restfultoolkitx of idea utility plug-in -- restful interface debugging

LabVIEW Arduino tcp/ip remote smart home system (project part-5)

L'outil de nettoyage des données flashtext améliore directement l'efficacité de plusieurs dizaines de fois
随机推荐
LabVIEW Arduino TCP/IP远程智能家居系统(项目篇—5)
中金证券经理的开户链接开户买股票安全吗?有谁知道啊
Some ways out for older programmers
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
[hybrid programming JNI] details of JNA in Chapter 11
美术向的Unity动画知识
Open world mecha games phantom Galaxy
Leetcode (452) - detonate the balloon with the minimum number of arrows
Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
Leetcode (763) -- dividing letter ranges
Detailed explanation of nmap parameters
Data governance does everything
YOLOv6:又快又准的目標檢測框架開源啦
C language: a simple calculator is implemented by using code many times
Share three methods of automatic summation in Excel
电子协会 C语言 1级 31 、 计算线段长度
Raspberry pie preliminary use
Homebrew installation in MacOS environment [email protected]
为什么我不推荐去SAP培训机构参加培训?
Leetcode (122) - the best time to buy and sell stocks II