#include <stdio.h> #include <stdlib.h> #define SIZE 4 void getInput(int num[]); int getLargest(int num[], int size); int main() { int i, largest, num[SIZE]; getInput(num); getLargest(num, SIZE); printf("The largest number is: %i. \n", getLargest(num, SIZE)); system("pause"); return 0; } void getInput(int num[]) { int i; for (i = 0; i < SIZE; i++) { printf("Enter a unique integer: "); scanf("%i", & num[i]); } } int getLargest(int num[], int size) { int i, largest; for (i = 0, largest = num[i++]; i < SIZE; i++) { if (num[i] > largest) { largest = num[i]; } } return largest; }
Takes input from user, then gives back the largest number from input. Array size can easily be changed through the constant SIZE. Notice the functions at the bottom. 🙂