1.c vector Դ??
2.c 中vector的用法详解
c vector Դ??
//只写了二维向量的,如果多维向量,-4的源码继续扩展就可以了
#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,java开放平台源码 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中的一种数据结构,确切的主力吞吐指标源码说是一个类。它相当于一个动态的杭州全网营销源码数组,当程序员无法知道自己需要的业绩新高指标源码数组的规模多大时,用其来解决问题可以达到最大节约空间的目的。