/*WAP to find smallest and largest number from array using DMA with new and delete operator. After destroying its memory with delete operator what will happen? Comment on your results.*/
#include<iostream.h>
int main()
{
int *p=new int[20];
int max;
int min;
int i,j,n,temp;
cout<<"How many numbers do you want? ";
cin>>n;
cout<<"Input "<<n<<" numbers: ";
for(i=0;i<n;i++)
cin>>*(p+i);
max=*(p+0);
min=*(p+0);
for(i=0;i<n;i++)
{
if(*(p+i)>max)
max=*(p+i);
else if(*(p+i)<min)
min=*(p+i);
}
cout<<"Smallest is: "<<min;
cout<<endl<<"Greatest is: "<<max;
return 0;
}
No comments:
Post a Comment