Skip to content

Instantly share code, notes, and snippets.

@rocket-fuel86
Created February 12, 2026 19:04
Show Gist options
  • Select an option

  • Save rocket-fuel86/5f5ee5a6f1b188f4cd7fe1d0e76a2930 to your computer and use it in GitHub Desktop.

Select an option

Save rocket-fuel86/5f5ee5a6f1b188f4cd7fe1d0e76a2930 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "functions.h"
int main()
{
const unsigned int LEN = 3;
double array[LEN] = {};
fillArray(array, LEN);
showArray(array, LEN);
std::cout << maxIndex(array, LEN) << std::endl;
std::cout << minIndex(array, LEN) << std::endl;
}
################################### functions.h ##################################################
#pragma once
#include <iostream>
void fillArray(double array[], const unsigned int arrayLength)
{
for (unsigned int i = 0; i < arrayLength; i++)
{
std::cin >> array[i];
}
}
void showArray(double array[], const unsigned int arrayLength)
{
for (unsigned int i = 0; i < arrayLength; i++)
{
std::cout << array[i] << ' ';
}
std::cout << std::endl;
}
int maxIndex(double array[], const unsigned int arrayLength)
{
double max = array[0];
int maxIndex = 0;
for (unsigned int i = 1; i < arrayLength; i++)
{
if (array[i] > max)
{
max = array[i];
maxIndex = i;
}
}
return maxIndex;
}
int minIndex(double array[], const unsigned int arrayLength)
{
double min = array[0];
int minIndex = 0;
for (unsigned int i = 1; i < arrayLength; i++)
{
if (array[i] < min)
{
min = array[i];
minIndex = i;
}
}
return minIndex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment