Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,270 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,449 people online right now. Registration is fast and FREE... Join Now!




Determine the largest of 10 numbers

 
Reply to this topicStart new topic

Determine the largest of 10 numbers, Homework Help Needed for simple largest number

paingpyi
14 Dec, 2006 - 10:26 AM
Post #1

New D.I.C Head
*

Joined: 14 Dec, 2006
Posts: 2


My Contributions
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!

CODE
#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
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Determine The Largest Of 10 Numbers
14 Dec, 2006 - 10:53 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Remove the ampersand "&" symbol from your printf statements. You only use the ampersand in a scanf statement.
CODE

printf("largest number is %d\n",largest);
printf("largest number is %d", seclargest);
printf("%d",abc);


User is offlineProfile CardPM
+Quote Post

shakti8ie
RE: Determine The Largest Of 10 Numbers
14 Dec, 2006 - 11:26 PM
Post #3

New D.I.C Head
*

Joined: 11 Dec, 2006
Posts: 21



Thanked: 1 times
My Contributions
CODE


#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: 14 Dec, 2006 - 11:46 PM
User is offlineProfile CardPM
+Quote Post

shakti8ie
RE: Determine The Largest Of 10 Numbers
14 Dec, 2006 - 11:44 PM
Post #4

New D.I.C Head
*

Joined: 11 Dec, 2006
Posts: 21



Thanked: 1 times
My Contributions
CODE


#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??
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:46PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month