algorithm to calculate maximum in arrays

December 31, 2010 at 12:16:04
Specs: Windows XP
how I can calculate the maximum in an array of integers??

See More: algorithm to calculate maximum in arrays

Report •


#1
December 31, 2010 at 12:19:35
Another homework question? Just iterate through the array and check which value is biggest. How much easier can it be?

Report •

#2
December 31, 2010 at 12:22:21
here is my problem I have this array (2 3 1 2 4 2) and I have to find the maximum of it...

Report •

#3
December 31, 2010 at 14:50:14
You are given this sort of problem for homework to make you think and learn. There's no point in asking others to do it for you.

If you really can't work out how to do this then perhaps computer programming is not your thing. Take a more appropriate course.


Report •

Related Solutions

#4
December 31, 2010 at 16:44:17
set max equal to element 0 of the array
loop through the array starting with element 1
if max is less than the current element, the current element becomes max

Report •

#5
January 2, 2011 at 08:52:34
its not a homework... I study this by myself.
thanks shutat but l did this and its not working ...

Report •

#6
January 2, 2011 at 09:55:24
This is very straightforward stuff and you've already been told how to do it, so it's difficult to know where you are going wrong. The best thing to do is to list the program that you have written; then we can have a look and see what you are doing wrong and give you a few hints. There's no point in us just listing a solution as you'll learn nothing that way.

Also it would be helpful to know which C/C++ compiler you are using and which Operating System. I'm quite happy to point you in the right direction once I see what you have tried so far.


Report •

#7
January 2, 2011 at 10:15:30
10x anyway you have been so helpful for me ijack :)...

Report •

#8
January 2, 2011 at 12:33:04
...and the program that you have written that doesn't work? Don't you want help with it?

Report •

#9
January 3, 2011 at 01:27:14
this program find the maximum in the array of integer...
#include <iostream.h>
void main()
{
int max,i,n,arr[100];
cin >>n;
for (i=0;i<n;i++)
cin>>arr[i];
max=arr[0];
for (i=1;i<n;i++)
if(arr[i]>max)
max=arr[i];
cout <<max;
}

Report •

#10
January 4, 2011 at 08:28:13
No, it started to work suddenly.. I think the problem was form my computer ...

Report •


Ask Question