Write a program in C++ to find the maximum number between two numbers using a pointer.
Test Data :
Input the first number : 5
Input the second number : 6
Expected Output :6 is the maximum number.
#include<iostream>
using namespace std;
int main()
{ int first,second,*f,*s;
f=&first;
s=&second;
cout<<"Enter first number"<<endl;
cin>>first;
cout<<"Enter second number"<<endl;
cin>>second;
if(*f>*s){
cout<<"Largest="<<*f<<" and smallest="<<*s<<endl;
}else{
cout<<"Largest="<<*s<<" and smallest="<<*f<<endl;
}
return 0;
}
Comments
Leave a comment