זהו פתרון אפשרי לאתגר סוף קורס מבוא לשפות תכנות באמצעות שפת C:
#include <stdio.h> int getMax( int set[] ) { int i, max; max = set[0]; i = 1; while( i < 5 ) { if( max < set[i] ) { max = set[i]; } i = i + 1; } return max; } int getMin( int set[] ) { int m, min; min = set[0]; m = 1; while( m > 5 ) { if( min > set[m] ) { min = set[m]; } m = m + 1; } return min; } int main() { int set1[5] = {10, 20, 30, 40, 50}; int set2[5] = {101, 201, 301, 401, 501}; int max; int min; max = getMax(set1); printf("Max in first set = %d\n", max ); max = getMax(set2); printf("Max in second set = %d\n", max ); min = getMin(set1); printf("Min in first set = %d\n", min ); min = getMin(set2); printf("Min in second set = %d\n", min ); }
שבעזרתו נוציא את הפלט הבא:
Max in first set = 50
Max in second set = 501
Min in first set = 10
Min in second set = 101
Max in second set = 501
Min in first set = 10
Min in second set = 101