variable name also should be exactly same. thank you in advance. Exercise P7.7.
ID: 3728873 • Letter: V
Question
variable name also should be exactly same.
thank you in advance.
Exercise P7.7. Write a function that reverses the values of an array of floating-point data: void reverse .double at, int a size) In the function, use two pointer variables, and not integer indexes, to traverse the array elements. ·Write the function reverse (double a[], int a.size ()) described in Problem P7.7. Write a program that reads in a list of numbers contiguously in an array double x[100]. The user may enter no more than 100 numbers (but less is ok). Let x size be the number of numbers entered by the user. Note x [100] serves as a storage and x size indicates theExplanation / Answer
Code of the avobe program is given below:
#include <iostream>
using namespace std;
void reverse(double a[],int a_size ){
cout<<"Reversed list: ";
for(int i=a_size-1;i>=0;i--) //for loop to reverse the array
{
cout<<a[i];
if(i>0){
cout<<",";
}
}
cout<<endl;
}
int main() {
double x[100];
int size,i=0; //size and counter
char sc; // flag to continue
do
{
size=0;
i=0;
cout<<"Enter the no elements of the list"<<endl;
cin>>size;
cout<<"Enter a list of numbers:";
while (i<size) //loop to enter the list
{
cin>>x[i];
i++;
}
reverse(x,size); // calling the function
cout<<"Continue (y/n)?";
cin>>sc;
}while(sc=='y'||sc=='Y');
}
Output:
Enter the no elements of the list
4
Enter a list of numbers:1 2 3 4
Reversed list: 4,3,2,1
Continue (y/n)?yEnter the no elements of the list
4
Enter a list of numbers:2 5 4 10
Reversed list: 10,4,5,2
Continue (y/n)?n
refer to the comments inline.
note: For any info drop a comment
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.