WAP to find the minimum and maximum element of the array by using functions.

 

#include <stdio.h>
int max(int arr[], int n) {
    int max = arr[0];
    for(int i=0; i<n; i++) {
        if (max < arr[i])
        max = arr[i];
    }
    return max;
}
int min(int arr[], int n) {
    int min = arr[0];
    for(int i=0; i<n; i++) {
        if (min > arr[i])
        min = arr[i];
    }
    return min;
}

int main()
{
    int n, arr[50], i;
    printf("Enter the number of element in an array: ");
    scanf("%d", &n);
    printf("Enter the elements in the array: ");
    for (i=0; i<n; i++)
    scanf("%d", &arr[i]);
    printf("The maximum element of array is %d\nThe minimum element of array is %d", max(arr, n), min(arr, n));

    return 0;
}

Comments

Popular posts from this blog

WAP that inputs two arrays and saves sum of corresponding elements of these arrays in a third array

WAP to add or to multiply two matrices of order nXn.

WAP that calculates the simple interest and compound interest. The principal amount, rate of interest and time are entered through the keyboard.