C++ One-dimensional Array Write a program that lets the user enter 10 values int
ID: 3760442 • Letter: C
Question
C++ One-dimensional Array Write a program that lets the user enter 10 values into an array. The program should then display the largest, the smallest, the sum, and the average values. The program output should be as shown below: The values are as following: The smallest value is: ??? The highest value is: ??? The sum is: ??? The average is: ??? can you show me that it works and run.. i want to use a while loop
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
system("pause");
return 0;
}
Explanation / Answer
#include<iostream.h>
#include<stdlib.h>
int main()
{
int a[10];
int i=0, sum=0, av,min,max,odd=0,ev=0;
cout<<"'Enter 10 values";
while(i<10)
{
cin>>a[i];
sum=sum+a[i];
i++;
}
av=sum/10;
min=a[0];
i=0;
while(i<10)
{
if(a[i]<min)
min=a[i];
i++;
}
i=0;
max=a[0];
while(i<10)
{
if(a[i]>max)
max=a[i];
i++;
}
cout<<"Sum is"<<sum<<endl;
cout<<"Average is"<<av<<endl;
cout<<"Highest value is"<<max<<endl;
cout<<"Minimum number"<<min<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.