Minimum element in an array in C


Q. Write a C program to find minimum element in an array.

#include <stdio.h>
#include <conio.h>
​
void main()
{
    int a[100], size, i, min;
    printf("Enter the number of elements in array\n");
    scanf("%d", &size);
    printf("Enter the integers: ");
    for (i = 0; i < size; i++)
    {
        scanf("%d", &a[i]);
    }
    min = a[0];
    for (i = 1; i < size; i++)
    {
        if (a[i] < min)
        {
            min  = a[i];
        }
    }
    printf("Minimum element in an array is %d", min);
    getch();
}

Q. Write an algorithm to find minimum element in an array.

1. Start
2. Declare an integer array `a` of size 100, integer variables `size`, `i`, `min`.
3. Print "Enter the number of elements in array".
4. Read the integer `size` from user input.
5. Print "Enter the integers:".
6. For `i` from `0` to `size - 1` do:
   1. Read the integer and store it in `a[i]`.
7. Initialize `min` with `a[0]`.
8. For `i` from `1` to `size - 1` do:
   1. If `a[i]` is less than `min` then
    - Set `min = a[i]`.
9. Print "Minimum element in an array is" followed by the value of `min`.
10. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.