C++ :: Pythagorean Triples - Natural Ones And Multiples

Aug 30, 2014

Okay, I'm hunting down Pythagorean triples. Both the natural ones, and the multiples.

What I would like, is to read in a value n, and then output every pythagorean triple for which the values <a,b,c> are less than or equal to n.

I have a working program. However, if you run this code and then compare it to the list here [URL] ....

You will notice that there are slight discrepancies. Not every multiple on that list, is found by my program. It's almost perfect, but I would like to at least understand why some are missing. My code is simple, so I will post it in its entirety.

#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cout << "a*a + b*b = c*c" << endl
<< "a,b,c are all integers" << endl

[Code] ....

View 2 Replies


ADVERTISEMENT

C :: Print All Pythagorean Triples With Length Of Hypotenuse

Oct 2, 2014

So this is a programming assignment right now that I'm working on. I was able to satisfy two or the requirements: to print all Pythagorean triples with the length of the hypotenuse being below the entered value and to state how many Pythagorean triples there are. I've come into a problem, though, since the final requirement is to state the largest Pythagorean triple. The problem is that it posts the values of a,b,c after the loop exits, which are going to be the values right below N (eg. N=19, then a,b,c=16,17,18).

Here is the program:

Code:
#include <stdio.h>
void main () {
int a,b,c,N;
int ctr = 0;

[Code] ....

My questions is how to fix this problem because putting it in the for loop will just cause it to repeat all values.

View 4 Replies View Related

Visual C++ :: Pythagorean Triples - Read Integer N And Print

Sep 27, 2014

I need to create a code in c fits the description below,

Description : 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+b
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).

View 1 Replies View Related

C :: Natural Log Program

Oct 16, 2014

I am working on a program to compute the natural log of numbers using several different methods, but I am having a couple of issues. Firstly, when using Borchardt's Algorithm I almost always end up with nan as a result, even though I am pretty sure I got the formula correct. Also, in my lnDemo.c file It doesnt give me the correct answer and the second time around I get a segmentation fault.

Code:

//myLog.h-------------------------------------------------------
//These functions will compute or aproximate the natural log of a number
//This method will use a formula to compute it
int lnFormula(double x, int m,double *result);

[code]....

View 7 Replies View Related

C++ :: Sum Of Multiples Less Than 100

May 23, 2013

What I want it to do is have the user input a number: ex. 5 and then have the code give the sum for all the multiples of 5 less than 100, so it should be equal to 950 in this example.

Anyway, I have got so far to get it to list the numbers, but I need the sum of those numbers without all the text displayed every time.

I have chosen to use the FOR, but I am wondering if I should implement WHILE loop in my coding somewhere.

Code:
#include <iostream>
using namespace std;
int addMultiples() {
// Start

[Code] ....

I want the output like this:

What multiples are we adding? 5

The sum of the multiples of 5 less than 100 are: 950

View 7 Replies View Related

C++ :: Display Matrix Of Multiples Of 4

Feb 25, 2013

Write a c++ program to display a matrix of multiples of 4 from 1 upto 30 .....

View 1 Replies View Related

C# :: Small Program That Will Create Multiples Of The Previous Line?

Apr 4, 2015

Im trying to do a small program that will create multiples of the previous line *2, and spit out the anwser in seperate lines (as many times as the user wants)

Example if i wrote it in a bad way

2
4
8
16
32
etc.

At this time my code looks likes this, now im planing to get my hands on the IF statment

using System;
using System.Collections.Generic;
using System.Linq;

[Code].....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved