C Program - Find smallest in an Array using function

#include<stdio.h>
// function min with parameter as array and array size(function prototype)
int min(int array[], int size);

int main()
{
//initialize array to 0
int arr[10] = { 0 };
int size = 10;
printf("Enter any 10 numbers = ");
// for loop to scan 10 elements
for (int i = 0; i < 10; i++)
{
scanf("%d", &arr[i]);
}
// passing the array and size and print smallest number on screen
printf("The smallest number is %d", min(arr, size));
getchar();

}
//Min function header
int min(int array[], int size)
{
//initailizing one element to compare the number
int element = array[0];
// for loop to compare array with smallest number
for (int i = 0; i < size; i++)
{
if (array[i]<element)
{
element = array[i];

}
}
// returning smallest number.
return element;
}

Comments

Popular posts from this blog

How to Block Websites without using any Software.

C Program - Greater, less and Equal

C Program - Even Odd