Thursday, 8 January 2015

C Program to find the Smallest Element in an Array


This is a C Program which finds the smallest largest element in an array.

Here initially first element in array and  its next element are compared array[0] and array[1] , if array[0] is greater, then the value is stored in array[0] and now the second element is increased 2 .3 4 .. until the last element is reached.

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n;
    printf("How many numbers ?\t");
    scanf("%d",&n);
    int array[n];
    for(i=0;i<n;i++)
    {
        printf("\nEnter number %d: \t",i+1);
        scanf("%d",&array[i]);
    }
    for(i=0;i<n;i++)
    {
        if(array[0]>array[i])
            array[0]=array[i];
    }
    printf("The smallest among the %d numbers is %d",n,array[0]);
    return 0;
}

OUTPUT :
C - Smallest Element in an Array

Related Programs :

No comments:

Post a Comment