By using an array, write a program:
*That asks user to enter 10 integers
*That display the 10 integers entered by a user
*That display the sum of the 10 integers
*That display the average of the 10 integers
*That display the minimum and maximum of the 10 integers
Please help me write this program. If possible, reply today.
You are lucky. I just read your post and I know the answer. I once recieved an assignment like this. Below are the answers.
#include <stdlib.h>
#include <iostream.h>
using namespace std;
// Declare user-defined functions
int min(int*, int);
int max(int*, int);
int main() {
// Declare and initialise variables
int number[10];
for ( int i = 0; i < 10; i++ )
number[i] = 0;
int sum = 0;
double average = 0.0;
int minNum = 0;
int maxNum = 0;
// Prompt user to enter 10 integers
cout << "Please enter 10 integers.\n\n";
for ( int j = 0; j < 10; j++ ) {
cout << "Enter integer #" << j + 1 << ": ";
cin >> number[j];
cout << "\n\n";
}
// Display user's entered integers
cout << "These were the numbers which you have entered:\n\n";
for ( int k = 0; k < 10; k++ ) {
cout << number[k] << " ";
}
cout << "\n\n";
// Display sum of integers
for ( int l = 0; l < 10; l++ ) {
sum += number[l];
}
cout << "Sum of all integers: " << sum;
cout << "\n\n";
// Display average of integers
average = (double)sum / 10;
cout << "Average of all integers: " << average;
cout << "\n\n";
// Display minimum and maximum of the 10 integers
minNum = min(number,10);
maxNum = max(number,10);
cout << "Minimum number: " << minNum << "\n\n";
cout << "Maximum number: " << maxNum << "\n\n";
system("pause");
return 0;
} // main function
int min( int* arrayVariable, int arraySize )
{
int minNumber = arrayVariable[0];
for ( int i = 1; i < arraySize; i++ )
if ( arrayVariable[i] < minNumber ) minNumber = arrayVariable[i];
return minNumber;
} // min function: finds the minimum number in the array
int max( int* arrayVariable, int arraySize )
{
int maxNumber = arrayVariable[0];
for ( int i = 1; i < arraySize; i++ )
if ( arrayVariable[i] > maxNumber ) maxNumber = arrayVariable[i];
return maxNumber;
} // max function: finds the maximum number in the array
You are lucky. I just read your post and I know the answer. I once recieved an assignment like this. Below are the answers.
#include <stdlib.h>
#include <iostream.h>
using namespace std;
// Declare user-defined functions
int min(int*, int);
int max(int*, int);
int main() {
// Declare and initialise variables
int number[10];
for ( int i = 0; i < 10; i++ )
number[i] = 0;
int sum = 0;
double average = 0.0;
int minNum = 0;
int maxNum = 0;
// Prompt user to enter 10 integers
cout << "Please enter 10 integers.\n\n";
for ( int j = 0; j < 10; j++ ) {
cout << "Enter integer #" << j + 1 << ": ";
cin >> number[j];
cout << "\n\n";
}
// Display user's entered integers
cout << "These were the numbers which you have entered:\n\n";
for ( int k = 0; k < 10; k++ ) {
cout << number[k] << " ";
}
cout << "\n\n";
// Display sum of integers
for ( int l = 0; l < 10; l++ ) {
sum += number[l];
}
cout << "Sum of all integers: " << sum;
cout << "\n\n";
// Display average of integers
average = (double)sum / 10;
cout << "Average of all integers: " << average;
cout << "\n\n";
// Display minimum and maximum of the 10 integers
minNum = min(number,10);
maxNum = max(number,10);
cout << "Minimum number: " << minNum << "\n\n";
cout << "Maximum number: " << maxNum << "\n\n";
system("pause");
return 0;
} // main function
int min( int* arrayVariable, int arraySize )
{
int minNumber = arrayVariable[0];
for ( int i = 1; i < arraySize; i++ )
if ( arrayVariable[i] < minNumber ) minNumber = arrayVariable[i];
return minNumber;
} // min function: finds the minimum number in the array
int max( int* arrayVariable, int arraySize )
{
int maxNumber = arrayVariable[0];
for ( int i = 1; i < arraySize; i++ )
if ( arrayVariable[i] > maxNumber ) maxNumber = arrayVariable[i];
return maxNumber;
} // max function: finds the maximum number in the array
I would not say that he/she is lucky. At this rate the OP will fail their C++ exam.
How do I delete my BYTES account? I've only used Bytes once in 2006. Now after about 3 years, I've opened this Bytes community again. I'm the most unactive member in Bytes. So, how do I delete my account?