Dear Praveen,
I hope you might be trying to find the greatest number from
the given number..
To find the maximum number we perform match with each and every element of
array with the variable "max".
At first "max" value shoud be initialized to the 1st element of the
array.i.e. max=num[0];
And then we perform comapring with each and every element
Here is how we can find the maximum number from given array.
*MY CODE*
**
int i,max,counter;
int num[20];
//accept values into the num[] array
max=num[0];// max value is initialized to the 1st element
for(counter=0;counter<20;counter++)
{
if(num[counter] > max))
max = num[counter];
}
Hence we got the max value
*END OF MY CODE*
*YOUR CODE*
**
*
int i,max,counter;
int num[20];
//accept values into the num[] array
for(counter=0;counter<20;counter++)
{
if((counter == 0)||(num[counter] > max))
{
max = num[counter];
// max value is initialized to the 1st element
when counter is 0...
}
}
Hence we got the max value
*
**
*END OF YOUR CODE*
*Difference between "MY CODE" and "YOUR CODE" is :*
**
In my Code Im initializing max value before the for loop
In Your Code max value is initialized in the for loop,that too when counter
value is 0.
I hope you got it....
On Fri, Oct 8, 2010 at 9:44 AM, Pravglad <[email protected]> wrote:
> if((counter == 0)||(num[counter] > max))
> max = num[counter];
>
> to find greatest number..
>
> why do we use || operator here??i am lost
>
> --
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]<javaprogrammingwithpassion%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en