Answer to Question #264304 in C++ for Amit

Question #264304

WAP using pointer to print greatest and smallest number present in an array (min 10 elements)


1
Expert's answer
2021-11-11T07:30:20-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS