0
count + and - numbers
How can write a program that reads an unspecified number of integers and determine the + and - that have been read and compute the average of the values
3 ответов
+ 7
Providing a code would ruin the fun for you, no? :>
I'm not proficient in JS, so I'll just write a C++ sample as to how I would do it.
int count, temp, pos_counter, neg_counter;
float sum;
pos_counter = neg_counter = 0;
cout << "How many numbers do you wish to input? : ";
cin >> count;
for (int i = 0; i < count; i++)
{
cout << "Input number : "; cin >> temp;
sum += temp;
if (temp > 0) pos_counter++;
if (temp < 0) neg_counter++;
}
cout << "You have " << pos_counter << " positive integers and " << neg_counter << " negative integers." << endl;
cout << "The mean of all input integers is " << sum/count;
+ 5
Query how many numbers to be input.
Use a for loop to receive the input.
Use conditional statement to evaluate the input and increment the counter for both + and - values.
Store each of the value to a sum variable and divide by the number of inputs to obtain average.
0
Thanks
But code will be clearer