c++已知两边和夹角求第三边的程序和另外两角程序

来源:百度知道 编辑:UC知道 时间:2024/06/07 09:06:16
#include <iostream>
#include<iomanip>
#include <cmath>

using namespace std;

void main(){
float m,n,a,b,c,d,e,h,j,k,i,x,angle,another,oangle1,oangle2;
cout<<"请输入两边的长和角度"<<endl;
cout<<"m=";
cin>>m;
cout<<"n=";
cin>>n;
cout<<"angle=";
cin>>angle;
a=2*m*n*cos(angle);
b=pow(m,2)+pow(n,2);
c=b-a;
z=sqrt(c);
j=pow(m,2);
k=pow(another,2);

d=i+j-pow(n,2);
e=2*m*another;
h=d/e;
i=acos(h);
x=180-i-angle;
cout<<fixed<<setprecision(4);
cout<<"第三边是"<<another<<endl;
cout<<"其他角度分别是"<<setw(6)<<i<<setw(6)<<x<<endl;}
数据的数值不准确,并且角度出现乱码,为什么,此处用余弦定理求的!

#include <iostream>
#include <iomanip>
#include <cmath>

#define PI 3.14159

using namespace std;

void main(){
//定义变量
float e1,e2,ag;//input
float eo,ao1,ao2;//out
float eot,ao1t;//tmp
//输入
cout<<"请输入两边的长和角度"<<endl;
cout<<"e1=";
cin>>e1;
cout<<"e2=";
cin>>e2;
cout<<"ag=";
cin>>ag;
//余弦定理求第三边
eot=e1*e1+e2*e2-2*e1*e2*cos(ag*PI/180); //角度弧度
eo=sqrt(eot);
//余弦定理求夹角1
ao1t=e2*e2-e1*e1-eot;
ao1t=ao1t/(2*e1*eo);
ao1=acos(ao1t)*180/PI;//ao1t也可不用
//角2省事了
ao2=180-ag-ao1;
//输出
cout<<fixed<<setprecision(4);
cout<<"第三边是"<<eo<<endl;
cout<<"其他角度分别是"<<setw(6)<<ao1<<"***"<<setw(6)<<ao2<<endl;
}

你的another根本没