C Program to Find Smallest Element in Array

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int small, array[50], size, i;
    printf("Enter Array Size  : ");
    scanf("%d",&size);
    printf("\n Enter array elements : ");
    for(i=0; i<size; i++)
    {
        scanf("%d",&array[i]);
    }
    printf("Searching for smallest number ...\n\n");
    small=array[0];
    for(i=0; i<size; i++)
    {
        if(small>array[i])
        {
            small=array[i];
        }
    }
    printf("Smallest Number = %d",small);
    getch();
}


Run:

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...