Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*===========================================================================================================
- Due Date: September 30, 2012
- Software Designer: Royon Reynolds
- Course: 420-306 (Fall 2012)
- Deliverable: Assignment #2: Pythgorean Numbers (Version 4)
- Description:
- ============================================================================================================*/
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- /*===========================================================================================================
- Function Prototypes
- ============================================================================================================*/
- void MakeList ( int&, int, int[] );
- /*===========================================================================================================
- Main
- ============================================================================================================*/
- int main()
- {
- int m, i, j, c, k, pythT, low, high;
- int mm;
- double xm, sqRoot;
- int pcan[20000];
- int pyth[20000];
- system("mode con cols=150");
- system("mode con lines=70");
- cout << "This program generates Pythagorean candidate numbers in a table.\n";
- cout << "Type integer candidate number size limit m\n";
- cin >> m;
- cout << "Type integer low number size limit m\n";
- cin >> low;
- cout << "Type integer high number size limit m\n";
- cin >> high;
- cout << endl << endl;
- k = -1;
- xm = m + 1; //find corresponding table-size mm for this limit
- mm = sqrt(xm/2.) +2;
- for ( i=1; i < mm - 1; i++ ) // begin row loop; note row mm [i.e. last] is empty
- { // handle columns
- for ( j= i + 1; j < mm; j++) // show p-candidates on rest of row
- { c = i*i + j*j;
- if(c >= low && c <= high)
- {
- MakeList( k,c,pcan);
- }
- }
- } // end the row loop
- for(i=0; i <= k; i++)
- { sqRoot = sqrt((double)pcan[i]); // checks if perfect square
- if(sqRoot == (int)sqRoot)
- { pyth[pythT]=pcan[i];
- pythT++;
- }
- }
- }
- /*===========================================================================================================
- Functions
- ============================================================================================================*/
- void MakeList(int &t, int r, int p[]) // creates a unique ordered list of Pythagorean candidates
- { int q =-1;
- int x;
- bool f=false;
- while(q < t && f==false)
- { q=q+1;
- if(r<p[q])
- { f=true;
- if(r!=p[q])
- { x=t;
- while(x>=q)
- { p[x+1]=p[x];
- x=x-1;
- }
- t=t+1;
- p[q]=r;
- }
- }
- }
- if(f==false)
- { t=t+1;
- p[t]=r;
- }
- cout<<"R = " << r;
- cout<<" T = " << t << endl;
- for (q = 0; q <= t; q++)
- {
- cout << setw(3) << q << ": "<< p[q] << endl;
- }
- cout << endl;
- system( "pause");
- }
Add Comment
Please, Sign In to add comment