Write C++ program and test a function void sort2num(int *p1, int *p2), the resul
ID: 3844420 • Letter: W
Question
Write C++ program and test a function void sort2num(int *p1, int *p2), the result is that p1 points to the larger number of the two, and p2 points to the smaller number of the two.
Write C++ program and test a function void sort2num(int *p1, int *p2), the result is that p1 points to the larger number of the two, and p2 points to the smaller number of the two.
Write C++ program and test a function void sort2num(int *p1, int *p2), the result is that p1 points to the larger number of the two, and p2 points to the smaller number of the two.
Explanation / Answer
#include<iostream.h>
int sort2num(int *p1, int *p2);
int sort2num(int *p1, int *p2)
{
int r;
r=(*p1>*p2)?*p1:*p2;
return(r);
}
int main()
{
int p1,p2;
cout<<"Enter 2 nos.: ";
cin>>p1>>p2;
cout<<"Greatest of two numbers is :"<<sort2num(&p1,&p2)<<" ";
}
the sample output is when we enter 56 and 78 .the greatest of two numbers is 78.by using void the function sort2num wouldn't run.
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.