Guest User

Untitled

a guest
Dec 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. /*===========================================================================================================
  2. Due Date: September 30, 2012
  3. Software Designer: Royon Reynolds
  4. Course: 420-306 (Fall 2012)
  5. Deliverable: Assignment #2: Pythgorean Numbers (Version 4)
  6.  
  7. Description:
  8. ============================================================================================================*/
  9. #include <iostream>
  10. #include <conio.h>
  11. #include <math.h>
  12. #include <iomanip>
  13. using namespace std;
  14. /*===========================================================================================================
  15. Function Prototypes
  16. ============================================================================================================*/
  17. void MakeList ( int&, int, int[] );
  18. /*===========================================================================================================
  19. Main
  20. ============================================================================================================*/
  21. int main()
  22. {
  23. int m, i, j, c, k, pythT, low, high;
  24. int mm;
  25. double xm, sqRoot;
  26. int pcan[20000];
  27. int pyth[20000];
  28.  
  29. system("mode con cols=150");
  30. system("mode con lines=70");
  31.  
  32.  
  33. cout << "This program generates Pythagorean candidate numbers in a table.\n";
  34. cout << "Type integer candidate number size limit m\n";
  35. cin >> m;
  36. cout << "Type integer low number size limit m\n";
  37. cin >> low;
  38. cout << "Type integer high number size limit m\n";
  39. cin >> high;
  40. cout << endl << endl;
  41.  
  42. k = -1;
  43. xm = m + 1; //find corresponding table-size mm for this limit
  44. mm = sqrt(xm/2.) +2;
  45.  
  46. for ( i=1; i < mm - 1; i++ ) // begin row loop; note row mm [i.e. last] is empty
  47. { // handle columns
  48. for ( j= i + 1; j < mm; j++) // show p-candidates on rest of row
  49. { c = i*i + j*j;
  50. if(c >= low && c <= high)
  51. {
  52. MakeList( k,c,pcan);
  53. }
  54. }
  55. } // end the row loop
  56. for(i=0; i <= k; i++)
  57. { sqRoot = sqrt((double)pcan[i]); // checks if perfect square
  58. if(sqRoot == (int)sqRoot)
  59. { pyth[pythT]=pcan[i];
  60. pythT++;
  61. }
  62. }
  63. }
  64. /*===========================================================================================================
  65. Functions
  66. ============================================================================================================*/
  67. void MakeList(int &t, int r, int p[]) // creates a unique ordered list of Pythagorean candidates
  68. { int q =-1;
  69. int x;
  70. bool f=false;
  71.  
  72. while(q < t && f==false)
  73. { q=q+1;
  74. if(r<p[q])
  75. { f=true;
  76. if(r!=p[q])
  77. { x=t;
  78. while(x>=q)
  79. { p[x+1]=p[x];
  80. x=x-1;
  81. }
  82. t=t+1;
  83. p[q]=r;
  84. }
  85. }
  86. }
  87. if(f==false)
  88. { t=t+1;
  89. p[t]=r;
  90. }
  91. cout<<"R = " << r;
  92. cout<<" T = " << t << endl;
  93.  
  94. for (q = 0; q <= t; q++)
  95. {
  96. cout << setw(3) << q << ": "<< p[q] << endl;
  97. }
  98. cout << endl;
  99. system( "pause");
  100. }
Add Comment
Please, Sign In to add comment