|
|
|
© 1998 by Bobby Griggs.
// Program name: Sum of numbers
// Purpose: To accept input of 20 numbers, store them in an
// array, recall them from the array, and display the sum.
// Win32 console application
#pragma hdrstop
#include < iostream.h >
#include < conio.h >
const MAX = 20;
void Get_numbers(int numbers[MAX]);
void Compute_sum(int numbers[MAX]);
void main()
{
int numbers[MAX];
Get_numbers(numbers);
Compute_sum(numbers);
return;
}
void Get_numbers(int numbers[MAX])
{
int i;
for (i = 0;i < MAX;i++)
{
cout << "Enter in number # " << i + 1 << " ... ";
cin >> numbers[i];
cout << endl;
}
return;
}
void Compute_sum(int numbers[MAX])
{
int i,sum = 0;
for (i = 0;i < MAX;i++)
sum += numbers[i];
cout << "The sum is " << sum << "!" << endl << endl;
cout << "Press any key to continue ... " << endl;
getche();
return;
}
|