Finding the smallest integers in the given range using array C++ code example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Finding the smallest integers in the given range using array in C++ programming
To show: How to search the smallest integer in the given range using array in C++ programming
// a program to find the smallest number in an array named balance, a simple search function
#include <iostream>
using namespace std;
#define n 10
int main(void)
{
int i;
float small, balance[n]={100.00,40.00,-30.00,400.00,60.00,-25.00,-24.00,0.00, 3.24,0.50};
small = balance[0];
// loop for displaying the array content
for(i=0; i<n; i++)
cout<<balance[i]<<" ";
// another loop do the array element comparing, verify until condition i=n
for(i=1; i<n> balance[i])
small = balance[i];
}
cout<<"\nSearching..."<<endl;
// display the result...
cout<<"The smallest value in the given array is = "<<small<<endl;
return 0;
}
Output example:
100 40 -30 400 60 -25 -24 0 3.24 0.5
Searching...
The smallest value in the given array is = -30
Press any key to continue . . .