Write a C program to read n elements in an array and find the minimum element of the array.

#include <stdio.h>
main()
{
    int arr[100],i,j,n,min=0;
    printf("\nEnter the number of elements : ");
    scanf("%d",&n);
    printf("\nEnter the elements :");
    for(i=0;i<n;i++)
    {       
        scanf("%d",&arr[i]);
    }
    printf("\nThe list is :");
    for (i=0;i<n;i++)
    {
        printf("%9d ", arr[i]);
    }
    printf("\n");
    for (i=1;i<n;i++)
    {
        if(arr[min]>arr[i])
        {
            min=i;
        }
    }
    printf("\nThe minimum element of the array=%d",arr[min]);
}

No comments:

Post a Comment