How to Find the Greatest Number in Array in C++

This is the simple C++ exercise for beginners to understand the arrays. The program will find out the greatest number in a given array e.g. in array [2,15,11,55,8,10] = 55 will be the greatest number.

Source Code 


#include "stdafx.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int min=0; int max=0; int num;
Console.WriteLine("Enter the number count : ";
int n;
cin>>n;
Console.WriteLine("";
cin>>num;
min = num;
for(int i=1;i<n;i++)
{
cin>>num;
if(num>max)
{
max=num;
}
if(num<min)
{
min=num;
}
}
Console.WriteLine("";
Console.WriteLine("Greatest is : "<< max;
int toPause;
cin>>toPause;
return 0;
}


Output of the Program 


 Find the Greatest Number in Array in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment