Thread: Pythagorean Numbers

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Unhappy Pythagorean Numbers

    hey i really need help, how can i generate a simple coding of pythagorean table where it reads the upper right triangle? together, how to get table parameters, use nested loops (which prints out the raw list of all Pythagorean-candidates (do not need to store in an array) & how to extract the pythagorean numbers? i would really really apreciate it, thanks y'all very much for support

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by NightLightSky View Post
    how can i generate a simple coding of pythagorean table where it reads the upper right triangle?
    Quote Originally Posted by NightLightSky View Post
    how to get table parameters
    Quote Originally Posted by NightLightSky View Post
    use nested loops (which prints out the raw list of all Pythagorean-candidates (do not need to store in an array)
    Quote Originally Posted by NightLightSky View Post
    how to extract the pythagorean numbers?
    sure, we'll help you out with all of your questions after youve made the slightest attempt to try yourself, and post your results/errors/specific questions.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Post my pythagorean code for now

    Code:
    #include <iostream>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    int main()
    {
    	int m, mm;
    	double xm;
    	int i, j;
    	int c;
    
    	//Get candidate-table dimensions
    	cout << "This program generates Pythagorean candidate numbers in a table.\n\n";
    	cout << "Type the absolute P-candidate maximum M:\n";
    	cin  >> m;
    
    	xm = m+1;
    	mm = sqrt(xm/2.);
    	cout << "The row/column size of the candidate table is: " << mm << "\n\n\n";
    
    	for( j = 2; j < mm; j++ )
    	{
    		cout << setw(5) << j;
    	}
    	cout << "\n\n";
    
    	//Generates table
    	for( i = 1; i < mm - 1; i++ )
    	{
    		cout << "R= " << setw(2) << i;
    
    		for( j = 2; j <= i; j++ )
    		{
    			c = (( i * i ) + ( j * j ));
    			cout << setw(5) << c;
    		}
    		cout << "\n";
    	}
    	cout << endl;
    
    	system( "Pause" );
    	return 0;
    }	//end main

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    upper

    but what i need is to display on the upper right side

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    to me:
    how can i generate a simple coding of pythagorean table where it reads the upper right triangle?
    is something different than:
    what i need is to display on the upper right side
    the first one seems like its some math thing that i dont know about ("upper right triangle"), the second one seems that you want some output to be right-aligned from the top of the screen. in this case, you have to figure out the "padding" (filling your output with spaces or some other character in order to make it look the way you want).

    say your monitor is N characters wide, and we have a character string of length K to print. how do you get this to appear "right-aligned"? N-K spaces (" ") followed by your output. for example, for an output line width of 5 and with string "abc" like (top line is column number:
    Code:
    12345
      abc
    if you do it this way, you would have to know how wide the output screen is (terminal or console window), because it isnt a fixed size. i dont do stuff like this and im not familiar with this tool, but i think "ncurses" may work.
    Last edited by nadroj; 09-15-2009 at 09:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. Replies: 4
    Last Post: 03-03-2003, 03:52 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM