-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path02_smallest.c
62 lines (49 loc) · 1.32 KB
/
02_smallest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// // Write a function to find the smallest number from the given array of any size. (TSRS)
// // Header Files
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// // Functions Declarations (Prototypes)
int smallest(int[], int);
void inputArray(int[], int);
// // Main Function Start
int main()
{
const int ARRAY_SIZE;
printf("\nHow Many Numbers You Want to Enter => ");
scanf("%d", &ARRAY_SIZE);
// // Check for Invalid Array Size
if (ARRAY_SIZE < 1)
{
puts("\n!!! Invalid Input, Plz Correctly Specify Number of Numbers...");
exit(0);
}
// // Declare Array of Variable size
int nums[ARRAY_SIZE];
// // Input Numbers
printf("\nEnter %d Numbers => ", ARRAY_SIZE);
inputArray(nums, ARRAY_SIZE);
printf("\nSmallest Number => %d", smallest(nums, ARRAY_SIZE));
putch('\n');
getch();
return 0;
}
// // Main Function End
// // Functions Definitions 👇👇
// // Function to Input Array Numbers
void inputArray(int nums[], int size)
{
for (int i = 0; i < size; i++)
scanf("%d", &nums[i]);
}
// // Function to Find Smallest Element of An Array
int smallest(int nums[], int size)
{
int smallest = nums[0];
for (int i = 1; i < size; i++)
{
if (nums[i] < smallest)
smallest = nums[i];
}
return smallest;
}