Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created November 3, 2025 17:39
Show Gist options
  • Select an option

  • Save juanfal/cbff080e1b12dd013934a2fb1f75e0e9 to your computer and use it in GitHub Desktop.

Select an option

Save juanfal/cbff080e1b12dd013934a2fb1f75e0e9 to your computer and use it in GitHub Desktop.
min of an array
// t9e06.minVec.cpp
// juanfc 2023-11-14
//
#include <iostream>
#include <array>
using namespace std;
// consts
const int N=3;
// types
typedef array<float,N> TVec;
int main()
{
void printArr(TVec a);
int minVec(TVec a);
TVec a = {{1, -22, 0}};
printArr(a); cout << endl;
cout << "Min value in it: "
<< minVec(a) // 1
<< endl;
a = (TVec){{0, 1, 0}};
printArr(a); cout << endl;
cout << "Min value in it: "
<< minVec(a) // 0
<< endl;
return 0;
}
int minVec(TVec a)
{
int min = a[0];
for (int i = 1; i < N; ++i)
if (a[i] < 0) min = a[i];
return min;
}
void printArr(TVec a)
{
for (int i = 0; i < N; ++i)
cout << a[i] << " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment