Thread: Easy programming help

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    1

    Post Easy programming help

    hey, I got this assignment to do and i need some help... im very new to this, please help,,

    task:
    Your assignment is to write a small C-program that has two variables ‘x’ and ‘y’, bothgiven two integer values (you can choose the values). The program should compare thevalue of these two variables and print out only the largest of these two values. Theprogram should work with any integer values of ‘x’ and ‘y’.

    anyone help me with code etc.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is your idea, what have you tried, and how does it not work?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2016
    Posts
    1
    First you declare 2 variable and compare this two variable. If your two variable is a and b you can write like this
    Code
    if(a>b)
    printf(" A is larger");
    else
    printf("B is larger");

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I'd recommend writing a function that takes two integers and returns the largest one.

    That way you can literally just write:
    Code:
    int const x = ...;
    int const y = ...;
    printf("%d\n", maximum(x, y));

  5. #5
    Registered User
    Join Date
    Jul 2016
    Posts
    4
    That's very simple all you have to do is compare both integers using an if-else statement

    Code:
    if(x > y)
      printf("x is larger than y");
    else
      printf("y is larger than x");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i need easy definition of c programming.
    By prashantphp76 in forum C Programming
    Replies: 1
    Last Post: 02-04-2015, 04:55 AM
  2. New to programming, this should be an easy one for you guys
    By pepperlizard in forum C++ Programming
    Replies: 3
    Last Post: 09-09-2012, 07:39 PM
  3. Easy way of learning c++ programming?
    By Ryan500 in forum C++ Programming
    Replies: 7
    Last Post: 07-14-2012, 08:27 AM

Tags for this Thread