WAP using pointer to print greatest and smallest number present in an array (min 10 elements)
#include<iostream>
using namespace std;
int main()
{
const int N=12;
int arrNum[N]={2,5,6,8,11,3,7,4,13,17,1,10};
cout<<"Primary Array:\n";
for(int* i=&arrNum[0];i!=&arrNum[N];i++)
{
cout<<*i<<" ";
}
int *smal=&arrNum[0];
for(int* i=&arrNum[0];i!=&arrNum[N];i++)
{
if(*i<*smal)
{
*smal=*i;
}
}
cout<<"\nThe smallest number present in an array is "<<*smal;
int *great=&arrNum[0];
for(int* i=&arrNum[0];i!=&arrNum[N];i++)
{
if(*i>*great)
{
*great=*i;
}
}
cout<<"\nThe greatest number present in an array is "<<*great;
}
Comments
Leave a comment