Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values
Answers
Answered by
0
Using C++ programming language
# include<iostream>
using namespace std;
int main()
{
int s=0 ;
int s1 = 0;
int sum=0;
int i,n;
cout<<" Enter the number of integers you would like enter " <<endl;
cin>>n;
int ar[n];
cout<<"Enter the values of the integers " <<endl;
for( i = 0 ; i < n-1 ; i ++) //loop to store the entered values in an array
{
cin>>ar[i];
}
for( i = 0 ; i < n-1 ; i ++) //this loop is used to perform the functions on the array elements
{
sum = sum + a[i];
if (ar[i] <0)
{
s = s+ i ;
}
else
{
s1 = s1 + i;
}
}
cout<<"The number of negative value " <<s<<endl;
cout<<"The number of positive value " <<s1<<endl;
cout<<"The sum of all the values " <<sum<<endl;
cout<<"The average of the input values " << (sum)/n <<endl;
}
Similar questions
English,
5 months ago
India Languages,
5 months ago
English,
5 months ago
Accountancy,
11 months ago
English,
11 months ago
Physics,
1 year ago
English,
1 year ago