Untitled
By: a guest | Feb 9th, 2010 | Syntax:
None | Size: 1.52 KB | Hits: 22 | Expires: Never
// ---------------------------------------------------------------
//
// This program reads a list of numbers from the command line and
// determines whether or not they are in descending order.
//
// usage:
// inlabAa number [number ...]
// ---------------------------------------------------------------
#include <cstdlib>
#include <iostream>
using namespace std;
const int SIZE = 10 // size of the array
int main(int argc, char *argv[])
{
int i; // loop counter
bool descending; // true if the list is in descending order
int list[size]; // array to hold the list
int lstSize; // the number of integers in the list
// Set listSize to the number of integers on the command line,
// or the size of the array, whichever is smaller.
if ( argc-1 > SIZE )
listSize = SIZE;
else
listSize = argc - 1;
// convert the numbers on the command line from ASCII to
// integer and store them in the list.
for (i = 1; i < listSize; i++)
list[i] = atoi(argv[i]);
// Check each pair of adjacent integers to see if the one with
// the lower index has a lower value.
for (i = 0, descending = true; (i < listSize) && descending; ++i)
descending = (list[i] > list[i+1]);
// Inform the user of the result
if (descending)
cout << "The list is in descending order.\n";
else
cout << "The list is NOT in descending order.\n";
return(descending);
}