C Write a program that declares three one dimensional arrays

C++.

Write a program that declares three one dimensional arrays named miles, gallons, and mpg. Each array should be declared in main() and should be capable of holding ten double-precision numbers. The numbers that should be stored in miles are 229.33, 307, 139.1, 220.6, 290.8, 189.9, 199.1, 163.7, 177.9, 193.16. The numbers should be stored in gallons are 10.1, 12.6, 4.7, 14.7, 17.3, 16.9, 13.2, 11.7, 7.3, 9.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the equivalent element of the gallons array. (e.g., mpg [0] = miles [0]/gallons [0]). Use pointers when calculating and displaying the elements of the mpg array.

Solution

#include<bits/stdc++.h>
using namespace std;



main()
{
double miles[10]={229.33,307,139.1,220.6,290.8,189.9,199.1,163.7,177.9,193.16};
double gallons[10]={10.1,12.6,4.7,14.7,17.3,16.9,13.2,11.7,7.3,9.4};
double mpg[10]={0};

double* mpgptr1=mpg;

for(int i=0;i<10;i++)
{
   *mpgptr1=miles[i]/gallons[i];
   mpgptr1++;
  
}

double* mpgptr2=mpg;

for(int i=0;i<10;i++)
{
   cout<<*mpgptr2<<\" \"<<endl;
   mpgptr2++;
  
}

return 0;

}

C++. Write a program that declares three one dimensional arrays named miles, gallons, and mpg. Each array should be declared in main() and should be capable of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site