Write a program that first reads at most 30 numbers of type double from the user
ID: 3935361 • Letter: W
Question
Write a program that first reads at most 30 numbers of type double from the user (the user will type character Quit when finished), and stores these values in an array in the same order that they were entered by the user. Your program should then call the function reverse array with this array as an argument, and finally displays the new contents of the array to the screen, 5 values per line. Sample Input/Output: (the user's input is shown in bold) Please enter at most 30 numbers; type quit when finished 1396 470 -9 -1 9180-5011 0 2 -275 13 216 15-7 quit The array in reverse order (5 values per line) is -715 216 13-275 2 0-5011 9180-1 -9 470 1396Explanation / Answer
Answer:
#include<iostream.h>
#include<conio.h>
void reverse(double a[],int i)
{
clrscr();
cout<<"after reverse ";
int k=i,m=0;
for(k=i-1;k>=0;k--)
{
cout<<a[k]<<" "; m++;
if(m==5)
{
cout<<" "; m=0;
}
}
}
void main()
{
clrscr();
char ch='f';
double a[30],i;
cout<<"enter atmost 30 no.";
while((ch!='n')&&(i!=31))
{
cin>>a[i];
i++;
cout<<"do you want to enter more(y/n)"; cin>>ch;
}
reverse(a,i);
getch();
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.