# How to Determine nad print the maximum number when 10 numbers are inpu

Page 1 of 1

## 4 Replies - 5568 Views - Last Post: 21 January 2007 - 10:57 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=23119&amp;s=ef45a0501099193e3f63f775553980f7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 oflah171

Reputation: 0
• Posts: 5
• Joined: 21-January 07

# How to Determine nad print the maximum number when 10 numbers are inpu

Posted 21 January 2007 - 06:50 AM

Hi all

I am just starting to learn C at the moment nad do not have currently have access to a compiler or the software to test it. I need to write a program that inputs a series of ten numbers and determines and prints the largest of these numbers. Below is my attempt but I am unsure it is correct. Can someone please advise. Thanks in advance.
Aoife

```int main (void)
{
int counter = 1;
int largest = 0;
int number;

while (counter is <=10 ) {
printf( ''Enter number: '' );
scanf( ''%d'' , &number);
largest = number /* store number in largest)
++counter
} /*end while*/

if (number > largest ) {
largest = number;
printf( ''largest number is %d\n'', largest );
} /*end if*/

return 0;

}

if (number > largest) {
```

Is This A Good Question/Topic? 0

## Replies To: How to Determine nad print the maximum number when 10 numbers are inpu

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: How to Determine nad print the maximum number when 10 numbers are inpu

Posted 21 January 2007 - 08:08 AM

Your current program will only store the final number entered by the user. You have the correct idea that you must check if the number entered is larger that the largest number stored, but you'll have to do that in your loop, or else store all entered values in an array and compare them later. You also seem to have an if statement outside of your main function. This will cause problems.

Your loop can run like this:

While entered values are less than 10
User enters a number
If the number entered is larger than the one in storage, replace the number in storage with the entered value.
End Loop

### #3 oflah171

Reputation: 0
• Posts: 5
• Joined: 21-January 07

## Re: How to Determine nad print the maximum number when 10 numbers are inpu

Posted 21 January 2007 - 09:51 AM

Is this right?

```while (counter is <=10 ) {
printf( ''Enter number: '' );
scanf( ''%d'' , &number);
largest = number /* store number in largest)
++counter
} /*end while*/

if (number > largest ) {
replace largest with number;
printf( ''largest number is %d\n'', largest );
} /*end if*/

return 0;
```

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: How to Determine nad print the maximum number when 10 numbers are inpu

Posted 21 January 2007 - 10:01 AM

Again, this will result in only the final number entered by the user being stored. You are checking the to see if the value entered is larger than the value stored, but you are only doing so once...you need to do so each time a number is entered. The user is entering numbers in your while loop. That is where the check should be taking place as well. Try something like the following:
```while (counter <=10 ) {
printf( "Enter number: ");
scanf( "%d": , &number);
if(number>largest)
{
largest = number;
}
++counter;
} /*end while*/
printf( "largest number is %d\n", largest );

```

### #5 oflah171

Reputation: 0
• Posts: 5
• Joined: 21-January 07

## Re: How to Determine nad print the maximum number when 10 numbers are inpu

Posted 21 January 2007 - 10:57 AM

Thanks a lot, makes more sence now!