// arrays example
#include <iostream>
usingnamespace std;
int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
int main ()
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
// arrays/readsum.cpp -- Read numbers into |
// arrays/reverse-input.cpp - Reverses order of numbers in input. |
// a program to find the smallest number in an array // named balance, a very simple search function #include <iostream> using namespace std; #define n 10 int main() { 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 array content.... for(i=0; i<n; i++) cout<<balance[i]<<" "; // another loop do the array element comparing... for(i=1; i<n; i++) // check until condition i = n { if(small > balance[i]) small = balance[i]; } cout<<"\nSearching..."<<endl; // display the result... cout<<"The smallest value in the given array is = " <<small<<endl; return 0; } |
0 Comments