Write a C++ program that reads 6 real numbers from the user (negative and positive numbers) into an array, then it does the following:  Display all the values of array in reverse order.  Find the sum and average of positive numbers of the array and display them.  Count negative numbers of the array and display it.  Find the minimum value of the array and display it.  Find the index of the minimum value of the array and display it.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 6RQ
icon
Related questions
Question

Write a C++ program that reads 6 real numbers from the user (negative and positive
numbers) into an array, then it does the following:
 Display all the values of array in reverse order.
 Find the sum and average of positive numbers of the array and display them.
 Count negative numbers of the array and display it.
 Find the minimum value of the array and display it.
 Find the index of the minimum value of the array and display it.

Expert Solution
Step 1: code
#include<iostream>
#include<iomanip>
using namespace std;

void reverse(int arr[], int size)
{
cout<< "\nArray in Reverse: ";
for(int j =0;j<6;j++)
{
cout<< arr[j]<<" ";
}
cout << endl;
}

void sumavgneg(int arr[], int size)
{
int poscount = 0;
int negcount = 0;
int sum = 0;

cout<< "\nAll positive numbers in array are: ";
for(int j =0;j<6;j++)
{
if(arr[j]>0)
{
sum += arr[j];
cout<< arr[j]<<" ";
poscount += 1;
}
}
cout<< "\nsum and average of positive numbers of the array : ";
cout << sum<<" and " << (sum/poscount)<<endl;
cout<< "\nAll Negative numbers in array are: ";
for(int j =0;j<6;j++)
{
if(arr[j]<0)
{
cout<< arr[j]<<" ";
negcount += 1;
}
}
cout << "\nTotal negative numbers are: "<<negcount<<endl;
}


int indexofSmallestElement(int array[], int size)
{
int index = 0;

for(int i = 1; i < size; i++)
{
if(array[i] < array[index])
index = i;
}

return index;
}


int main(){
int array[6],i=0,index;
cout << "\nEnter 6 number seperated by space: ";
for (int j = 5;j>=0;j--)
{
cin >> array[j];
}

reverse(array,6);
sumavgneg(array,6);
index = indexofSmallestElement(array,6);
cout<<"\nIndex of minimum element is: "<<index<<" and element is: "<<array[index]<<endl;

return 0;
}
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr