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;
}
0 comments:
Post a Comment