You are viewing a single comment's thread from:

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

in #developers2 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; 

}

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 76416.42
ETH 2864.57
USDT 1.00
SBD 2.57