# lowest number (array)

Page 1 of 1

## 2 Replies - 3927 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=6b4f03bb2a8b20744aea93aa27971348&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ziamie19

• New D.I.C Head

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: 944
• Posts: 2,464
• 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

Was This Post Helpful? 0

### #3 Soura

• New D.I.C Head

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*/

```

Please try this.
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }