C/C++代码实现向量叉乘

 行列式计算叉乘,以下是公式

相关代码如下:

 

c++代码:
#include<iostream>
using namespace std;
int main()
{
	int a, b, x1, x2, y1, y2, z1, z2, h, m, n;
	cout << "请输入向量a:";
	cin >> x1 >> y1 >> z1;
	cout << "请输入向量b:";
	cin >> x2 >> y2 >> z2;
	h = y1 * z2 - z1 * y2;  //计算三阶行列式
	m = z1 * x2 - x1 * z2;
	n = x1 * y2 - y1 * x2;
	cout << "( "<<h <<" "<< m <<" "<< n <<" )"<< endl;
	return 0;
}

C语言代码:
#include<stdio.h>
void chacheng()
{
	double a,b,c,d,e,f,x,y,z;
	printf("请输入向量a:");
	scanf("%lf %lf %lf",&a,&b,&c);
	printf("请输入向量b:");
	scanf("%lf %lf %lf",&d,&e,&f);
	x=b*f-c*e;        //计算三阶行列式
	y=c*d-a*f;
	z=a*e-b*d;
	printf("aXb=(%lf %lf %lf)\n",x,y,z);
}
int main()
{
	chacheng();
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值