1.c vector Դ??
2.c 中vector的用法详解
c vector Դ??
//只写了二维向量的,如果多维向量,百傢樂源码继续扩展就可以了
#include <stdio.h>
#include <math.h>
typedef struct vector{
float x;
float y;
}Vector;
float norm(Vector v){
return sqrt(v.x*v.x+v.y*v.y);
}
float dotmuti(Vector u,楚国联盟源码 Vector v){
return u.x*v.y+u.y*v.x;
}
// a's project on b
Vector project(Vector a, Vector b){
Vector temp;
float c;
if (norm(b) > 0)
c = dotmuti(a,b) / norm(b) / norm(b);
else
c = 0;
temp.x = b.x * c;
temp.y = b.y * c;
return temp;
}
int main()
{
Vector a;
Vector b;
// input vector a
printf("Pls input the first vector x and y\n");
printf("x:\n");
scanf("%f",&a.x);
printf("y:\n");
scanf("%f",&a.y);
//input vector b;
printf("Pls input the second vector x and y\n");
printf("x:\n");
scanf("%f",&b.x);
printf("y:\n");
scanf("%f",&b.y);
//output the vector
printf("Vector(%f, %f)'s projection on Vector(%f, %f) is: Vector(%f, %f).\n", a.x, a.y, b.x,b.y,project(a,b).x,project(a,b).y);
}
c 中vector的用法详解
c中vector的用法详解如下:
vector(向量):C中的一种数据结构,确切的幽冥传奇源码编译说是一个类。它相当于一个动态的商城类架构源码数组,当程序员无法知道自己需要的发邮件程序源码数组的规模多大时,用其来解决问题可以达到最大节约空间的目的。
2024-11-23 03:12
2024-11-23 03:05
2024-11-23 02:57
2024-11-23 02:43
2024-11-23 02:32
2024-11-23 02:16
2024-11-23 01:31
2024-11-23 00:59