# Determine the largest of 10 numbers

Page 1 of 1

## 3 Replies - 22407 Views - Last Post: 15 December 2006 - 12: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=22069&amp;s=53953dd975807ab79fc7d2ea9a020259&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 paingpyi

Reputation: 0
• Posts: 2
• Joined: 14-December 06

# Determine the largest of 10 numbers

Posted 14 December 2006 - 11:26 AM

I'm writing a problem with while loop to receive 10 numbers from user input and find Largest value. It's very simple without any high technique.
I've written following code but cannot output correct number.

#include <stdio.h>
#include <math.h>

int main()
{

int num=0;
int largest=0;
int seclargest=0;
int counter=0;
int abc=3;

while ( counter <= 3 ) // Begin 1st while loop
{

printf("Enter a number=");
scanf("%d",&num);
printf("\n");

if ( num > largest ) // Begin loop to determine the largest of 10 numbers entered by user from the keyboard
largest = num;

counter++;
}
printf("largest number is %d\n",&largest);
printf("largest number is %d",&seclargest);
printf("%d",&abc);
printf("\n");
return 0;

return 0;
}

edit: modified title ~ jayman9

Is This A Good Question/Topic? 0

## Replies To: Determine the largest of 10 numbers

### #2 Jayman

• Student of Life

Reputation: 421
• Posts: 9,532
• Joined: 26-December 05

## Re: Determine the largest of 10 numbers

Posted 14 December 2006 - 11:53 AM

Remove the ampersand "&" symbol from your printf statements. You only use the ampersand in a scanf statement.
printf("largest number is %d\n",largest);
printf("largest number is %d", seclargest);
printf("%d",abc);

### #3 shakti8ie

Reputation: 3
• Posts: 21
• Joined: 11-December 06

## Re: Determine the largest of 10 numbers

Posted 15 December 2006 - 12:26 AM

#include <stdio.h>

int main()
{
int num[10];
int i=0;
int largest;

while(i<10)
{
printf("Enter number[%d]:",i+1);
scanf("%d",&num[i]);
i++;
printf("\n");
}

largest=num[0];
i=0;
while(i<10)
{
if(num[i]>largest)
{
largest=num[i];

}
i++;
}

printf("\nLargest number is : %d\n",largest);

return 0;

}

Consider this code implemented using only while loops...so many variables are not required...implement array structure possible...again u have used 2 return 0; statements...I am working on another implementation of this problem without using array...

This post has been edited by shakti8ie: 15 December 2006 - 12:46 AM

### #4 shakti8ie

Reputation: 3
• Posts: 21
• Joined: 11-December 06

## Re: Determine the largest of 10 numbers

Posted 15 December 2006 - 12:44 AM

#include <stdio.h>

int main()
{
int i=0;
int largestNum,tempNum;
printf("Enter number[%d]:",++i);
scanf("%d",&tempNum);
largestNum=tempNum;

while(i<10)
{
printf("Enter number[%d]:",i+1);
scanf("%d",&tempNum);
if(tempNum>largestNum)
largestNum=tempNum;
i++;
}

printf("\nLargest number is : %d\n",largestNum);

return 0;

}

This is the second edition of the program without using array...only while loop...got it??