Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 17:07
Show Gist options
  • Save nalin-adh/81a335060ede812a9f78 to your computer and use it in GitHub Desktop.
Save nalin-adh/81a335060ede812a9f78 to your computer and use it in GitHub Desktop.
A C++ program to find the largest and smallest among n numbers.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n;
cout<<"How many numbers : ";cin>>n;
int *p=new int(n);
cout<<"\nEnter the "<<n<<" numbers : \n";
for(int i=1;i<=n;i++){
cin>>*(p+i);
}
int smallest = *p, largest= *p;
for(int i=1;i<=n; i++){
if((smallest>*(p+i))){
smallest=*(p+i);
}
if(largest<*(p+i))
largest=*(p+i);
}
cout<<"\nLargest number = "<<largest;
cout<<"\nSmallest number = "<<smallest;
getch();
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment