Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write this program in C++. Write a small program that fills an array of doubles

ID: 3767935 • Letter: W

Question

Write this program in C++. Write a small program that fills an array of doubles with user input, prints the doubles on the screen in a column, and adds up all the doubles in the array and prints the sum onto the screen. -You must use at least 3 functions - Declare an array of doubles of size 20. - Ask the user how many doubles to enter <= 20. - Use a loop to read the doubles into the array from the user. - Use a loop to print the array onto the screen in a column. - Use a loop to add up all the items in the array and store the sum - print the sum onto the screen

Explanation / Answer

#include<iostream.h>
#include<conio.h>

void fill(double a[], int n)
{
   for(int i=0;i<n;i++)
   {
       cout<<"Enter number";
       cin>>a[i];
   }
}

void print(double a[], int n)
{
   cout<<"Array input is";
   for(int i=0;i<n;i++)
   {

       cout<<a[i]<<endl;
   }
}

double sum(double a[], int n)
{
   double s=0;
   for(int i=0;i<n;i++)
   {
       s=s+a[i];          

   }
   return s;
}
void main()
{
   double a[20];
   int n;
   cout<<"Enter how many doubles to enter <=20";
   cin>>n;
   fill(a,n);
   print(a,n);
   double tot=sum(a,n);
   cout<<"Sum of all numbers is"<<tot;
   getch();
}