Solved

C programming

Posted on 2006-11-20
2
157 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
Comment Utility
#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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
factory design pattern vs abstract factoy design pattern 2 83
scoresClump  challenge 31 108
for loop with Set 4 45
count8 challlenge 13 85
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…
This is about my first experience with programming Arduino.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

16 Experts available now in Live!

Get 1:1 Help Now