[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C programming

Posted on 2006-11-20
2
Medium Priority
?
172 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 200 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

This is about my first experience with programming Arduino.
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.
Simple Linear Regression
Introduction to Processes

656 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