CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2014

    Pythagorean triples in code c, help!

    I need to create a code in c fits the description below, I have no idea what to do, if someone could possibly write a code or explain to me what I could do that would be appreciated!

    A positive integer triple (a, b, c) with 0 < a < b < c and a^2 + b^2 = c^2
    is called a Pythagorean triple. Write a
    program in C which reads an integer N and prints
    1. the total number of Pythagorean triples (a, b, c) with c < N,
    2. every such Pythagorean triple, and
    3. the triple that has the largest value of c.
    Hint: you can enumerate all possible pairs (a, b) with 0 < a < b < N and check if they satisfy a
    2 < N2
    Example Input/Output
    Enter a positive integer: [3]
    There is no Pythagorean triple in this range.
    Enter a positive integer: [15]
    There are 3 Pythagorean triples in this range:
    (3, 4, 5)
    (5, 12, 13)
    (6, 8, 10)
    The triple with the largest value of c is (5, 12, 13).
    Enter a positive integer: [6]
    There are 1 Pythagorean triples in this range:
    (3, 4, 5)
    The triple with the largest value of c is (3, 4, 5).

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Pythagorean triples in code c, help!

    This seems like a homework assignment. Please see http://forums.codeguru.com/showthrea...ork-assignment

    With what exactly are you having difficulty? You are given a good description of the problem. Just saying you have no idea isn't really going to illicit much help as nobody here is going to do your homework assignment for you.

    First think about how you would solve this problem using pen and paper. Then design the program from this, code it and finally test and debug it. Once you have produced some code if you post it here we;ll provide further advice and guidance.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)