lowest number (array)

Page 1 of 1

2 Replies - 3649 Views - Last Post: 11 October 2008 - 04:44 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=67126&amp;s=9ad657e5c0487b52918241e332d3ca96&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 ziamie19

Reputation: 0
• Posts: 7
• Joined: 04-October 08

lowest number (array)

Posted 10 October 2008 - 10:29 PM

```for(a=0;a<5;a++)
{ low = b[0];
if (b[a] <= low)
{ low = b[a]; }
}
cout<<"\n\nThe lowest entered number/s is "<<low;
```

what's wrong with this code??? the result is wrong. . .
plz help me. . . . .

Is This A Good Question/Topic? 0

Replies To: lowest number (array)

#2 Bench

• D.I.C Lover

Reputation: 859
• Posts: 2,343
• Joined: 20-August 07

Re: lowest number (array)

Posted 11 October 2008 - 12:55 AM

Check what happens as the first instruction of each iteration of your for block -

For each element within your array b, you have set your low variable to to the first element in the array (The array will not change, therefore low will be the same each time it comes to the comparison). As a result, the comparison statement always compares each element to the one at position 0 (Which may or may not be the lowest depending on the data)

Setting low to the first element once is a good idea, you would typically need it to happen before the for statement begins

This post has been edited by Bench: 11 October 2008 - 01:00 AM

#3 Soura

Reputation: 0
• Posts: 27
• Joined: 24-September 08

Re: lowest number (array)

Posted 11 October 2008 - 04:44 AM

ziamie19, on 10 Oct, 2008 - 10:29 PM, said:

plz help me. . . . .

The prog. to find the lowest between 10 No.s is-
```#include<stdio.h>
#include<conio.h>
#include<iostream.h>

main()
{
int a[10],i, min;
for(i=0; i<=9; i++)
{
printf("Input the marks%d=",i+1);
scanf("%d", &a[i]);
}
min=a[0];
for(i=0; i<=9; i++)
{
if(a[i]<min)
min=a[i];
}
printf("The Lowest marks is=%d",min);
getch();
}
/*end of main*/

```