RE: Hi, this is a test post, its main purpose will be posts in comments.

You are viewing a single comment's thread from:

Hi, this is a test post, its main purpose will be posts in comments.

in developers •  2 years ago 

#include <stdio.h>

//Function to find the largest element
int largestElement(int arr[], int size)
{
int max = arr[0];

for (int i = 1; i < size; i++) 
if (arr[i] > max) 
    max = arr[i]; 

return max;
}

//Function to find the smallest element
int smallestElement(int arr[], int size)
{
int min = arr[0];

for (int i = 1; i < size; i++) 
if (arr[i] < min) 
    min = arr[i]; 

return min;
}

// main()
int main()
{
int arr[] = {10, 324, 45, 90, 9808};
int n = sizeof(arr)/sizeof(arr[0]);

printf("Largest element in array is: %d \n",  largestElement(arr, n)); 
printf("Smallest element in array is: %d \n", smallestElement(arr, n)); 
return 0; 

}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!