Solved

C programming

Posted on 2006-11-20
2
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 122
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 57
ejb entity bean example 2 51
Java pass by reference 3 68
This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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…

740 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