Please help me finish solving this problem. Thank you. Write a program that can
ID: 3545723 • Letter: P
Question
Please help me finish solving this problem. Thank you.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
const int N=2;
int *p=new int[N];
bool moreInput=true;
int a;
char ans;
int size =0;
while(moreInput)
{
cout<< "More? (y/n) ";
cin>>ans;
if(ans=='y')
{
cin>>a;
p[size]=a;
size+=1;
}
else
moreInput=false;
}
for(int i=0;i<size;i++) {
for(int j=i+1;j<size;j++) {
if(p[i]>p[j]) {
int temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
cout<<" The sorted array : ";
for(int i=0;i<size;i++) {
cout<<" "<<p[i];
}
return 0;
}
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.