#include "mtl/mtl.h"
#include "mtl/utils.h"
#include "mtl/linalg_vec.h"
using namespace mtl;
using namespace std;
//begin
typedef external_vec<float> Vec;
//end
/*
Sample Output
[5,-3,-4,6,0,]
Largest element in the vector x is at location 3
*/
int
main()
{
//begin
const int N = 5;
float dx[] = { 5.0, -3.0,-4.0, 6.0 , 0.0 };
Vec x(dx, N);
int imax = max_index(x);
//end
print_vector(x);
cout << "Largest element in the vector x is at location "
<< imax << endl;
return 0;
}
#include "mtl/utils.h"
#include "mtl/linalg_vec.h"
using namespace mtl;
using namespace std;
//begin
typedef external_vec<float> Vec;
//end
/*
Sample Output
[5,-3,-4,6,0,]
Largest element in the vector x is at location 3
*/
int
main()
{
//begin
const int N = 5;
float dx[] = { 5.0, -3.0,-4.0, 6.0 , 0.0 };
Vec x(dx, N);
int imax = max_index(x);
//end
print_vector(x);
cout << "Largest element in the vector x is at location "
<< imax << endl;
return 0;
}
此博客展示了一段C++代码,包含多个头文件,定义了一个浮点型向量类型。在主函数中,创建了一个向量并初始化,通过max_index函数找到向量中最大值的索引,最后输出向量和最大值的位置。
2099

被折叠的 条评论
为什么被折叠?



