Solved

C programming

Posted on 2006-11-20
2
163 Views
Last Modified: 2010-04-16
Hi i'm new to C programming and need some help with writing a program.

Im trying to write a program that will read 3 numbers from the keyboard and print the largest one on the screen.

I have to only use 2 variables, 1 to read the numbers and one to hold the highest value.

I would be most grateful for any help

0
Comment
Question by:DexTexMex
2 Comments
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 50 total points
ID: 17981804
#include <stdio.h>

int main()
{
int xRead, xMax;

printf("\nEnter first value:");
scanf("%d", &xRead);
xMax = xRead;
printf("\nEnter second value:");
scanf("%d", &xRead);
if (xMax < xRead)
    xMax = xRead;
printf("\nEnter third value:");
scanf("%d", &xRead);
if (xMax < xRead)
    xMax = xRead;
printf("\nMax value was: %d", xMax);
}

Now, a note:  if your instructor has any grip at all, he may ask you to explain why each part of this works the way it does.  I'm going to leave that as an exercise for you.  This is pure C, not C++, so make sure that is what you are using.

Good luck.


0
 
LVL 1

Expert Comment

by:seanyp_2007
ID: 17981915
Here is a possible solution

#include <stdio.h>
#include <conio.h>

void main(){
      int Num=0, nVal;

      printf("Enter three numbers followed by return. 0 to END\n");
      do{
            scanf("%d",&nVal);
            if(nVal > Num)
            {
                  Num = nVal;
            }
      }while(nVal != 0 );
      printf("The largest number is : %d",Num);
      getche();
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 125
split53 challenge 7 109
Modify a small python script 19 116
what is the best portable software where i can test codes written in different languages 1 54
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question