how I can calculate the maximum in an array of integers??

Another homework question? Just iterate through the array and check which value is biggest. How much easier can it be?

here is my problem I have this array (2 3 1 2 4 2) and I have to find the maximum of it...

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.

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

its not a homework... I study this by myself.

thanks shutat but l did this and its not working ...

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.

10x anyway you have been so helpful for me ijack :)...

...and the program that you have written that doesn't work? Don't you want help with it?

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;

}

No, it started to work suddenly.. I think the problem was form my computer ...

Ask Your Question

Weekly Poll