Software & Finance





Turbo C - Find Smallest of N Numbers





Here is a simple program explains the concept of an array and finds the smallest of given N numbers.


Source Code


#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <bios.h>

#include <ctype.h>

 

#include MAX_NUMBERS 10

 

void main()

{

        int i, small, numbers[MAX_NUMBERS];

       

        for(i = 0; i < MAX_NUMBERS; i++)

        {

            printf("Enter [%d] Number: ", i + 1);

            scanf("%d", &numbers[i]);

        }

        small = numbers[0];

        for(i = 1; i < MAX_NUMBERS; i++)

        {

            if(small > numbers[i])

                small = numbers[i];

        }

        printf("Smallest Number: %d\n", small);

}

Output


Enter 1 Number: 10

Enter 2 Number: 8

Enter 3 Number: 6

Enter 4 Number: 4

Enter 5 Number: 2

Enter 6 Number: 3

Enter 7 Number: 5

Enter 8 Number: 1

Enter 9 Number: 9

Enter 10 Number: 9

 

Smallest Number: 1