Solved

C programming

Posted on 2006-11-20
2
158 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now