//Demonstration program for the function scale. #include #include void scale(int a[], int size); //Precondition: a[0] through a[size-1] each have a nonnegative value. //Postcondition: a[i] has been changed to the number of 1000s (rounded to //an integer) that were originally in a[i], for all i such that 0 <= i <= size-1 int round(double number); //Precondition: number >= 0. //Returns number rounded to the nearest integer. int main( ) { int some_array[4], index; cout << "Enter 4 numbers to scale: "; for (index = 0; index < 4; index++) cin >> some_array[index]; scale(some_array, 4); cout << "Values scaled to the number of 1000s are: "; for (index = 0; index < 4; index++) cout << some_array[index] << " "; cout << endl; return 0; } void scale(int a[], int size) { for (int index = 0; index < size; index++) a[index] = round(a[index]/1000.0); } //Uses math.h: int round(double number) { return floor(number + 0.5); }