Advertisement
StormWingDelta

GCF_tester

Jan 8th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. void GCF(int First, int Second)
  2. {
  3.  
  4.     int Dev1 = 0, Dev2 = 0;
  5.     int LoopCount = 0, FUP = 0, SUP = 0;
  6.     int FA[1000],SA[1000];
  7.     //printf("Filling Arrays!\n");
  8.     for(int F1 = 0; F1 < First; F1++)
  9.     {
  10.         FA[F1] = 0;
  11.     }
  12.     for(int S1 = 0; S1 < Second; S1++)
  13.     {
  14.         SA[S1] = 0;
  15.     }
  16.  
  17.     //printf("Generating Compareable Numbers! \n");
  18.     if(First > Second)
  19.     {
  20.         LoopCount = First;
  21.     }
  22.     else if(Second > First)
  23.     {
  24.         LoopCount = Second;
  25.     }
  26.     else if(First == Second)
  27.     {
  28.         LoopCount = First;
  29.     }
  30.     //printf("The LoopCount is : %d \n",LoopCount);
  31.     //Generate Numbers For Arrays
  32.     //gets all facotrs of both numbers
  33.     for(int Go = 1; Go <= LoopCount; Go++ )
  34.     {
  35.         //printf("Loop Number : %d \n\n",Go);
  36.         if(Go <= First)
  37.         {
  38.             Dev1 = (First / Go);
  39.            
  40.             if(IsWholeNumber(First, Go))
  41.             {
  42.                 //printf("%d : %d \t",First, Dev1);
  43.                 FA[FUP] = Dev1;
  44.                 FUP++;
  45.             }
  46.         }
  47.         if(Go <= Second)
  48.         {
  49.             Dev2 = (Second / Go);
  50.            
  51.             if(IsWholeNumber(Second, Go))
  52.             {
  53.                 //printf("%d : %d \n\n",Second, Dev2);
  54.                 SA[SUP] = Dev2;
  55.                 SUP++;
  56.             }
  57.         }
  58.     }
  59.     //printf("End Of Number Generating!\n\n\n\n");
  60.  
  61.     //printf("Starting Comparison!\n");
  62.     //Compare Numbers Of Arrays
  63.     for(int F = 0; F < First; F++)
  64.     {
  65.         for(int S = 0; S < Second; S++)
  66.         {
  67.             if( (FA[F] == SA[S]) && (FA[F] != 0) && (SA[S] != 0) )
  68.             {
  69.                 cout << First << " : "<< FA[F] << "   " << Second << " : " << SA[S] << endl;
  70.             }
  71.         }
  72.     }
  73.  
  74. }
  75. //The whole number getting system that goes with this.
  76. bool IsWholeNumber(int TestNum, int DividedBy)
  77. {
  78.     int EndResult = 0, Quotient = 0;
  79.     Quotient = TestNum / DividedBy;
  80.     EndResult = Quotient * DividedBy;
  81.  
  82.     if(EndResult == TestNum)
  83.     {
  84.         return true;
  85.     }
  86.     else
  87.     {
  88.         return false;
  89.     }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement