Determine the largest of 10 numbers

Homework Help Needed for simple largest number

Page 1 of 1

3 Replies - 10501 Views - Last Post: 15 December 2006 - 12:44 AM Rate Topic: -----

#1 paingpyi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
please help me!

#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  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • 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);


Was This Post Helpful? 0
  • +
  • -

#3 shakti8ie  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#4 shakti8ie  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • 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??
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1