Created
November 10, 2015 17:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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