Write a program to read an array of n numbers and then find the smallest number

Program in C

#include <stdio.h>
#include <conio.h>
void read_array(int arr[], int n);
int find_small(int arr[], int n);
int main()
{
int num[10], n, smallest;
clrscr();
printf("\n Enter the size of the array : ");
scanf("%d", &n);
read_array(num, n);
smallest = find_small(num, n);
printf("\n The smallest number in the array is = %d", smallest);
getch();
return 0;
}
void read_array(int arr[10], int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\n arr[%d] = ", i);
scanf("%d", &arr[i]);
}
}
int find_small(int arr[10], int n)
{
int i = 0, small = arr[0];
for(i=1;i<n;i++)
{
if(arr[i] < small)
small = arr[i];
}
return small;
}

Output

Enter the size of the array : 5
arr[0] = 1
arr[1] = 2
arr[2] = 3
arr[3] = 4
arr[4] = 5
The smallest number in the array is = 1

Leave a Comment