SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int gcf(int firstint, int secondint) /// function for calling the function
  4. {
  5. if (secondint!=0){
  6. return gcf(secondint, firstint%secondint); /// use of recursion
  7. }else{
  8. return firstint;
  9. }
  10. }
  11. int main()
  12. {
  13. int firstint = 0;
  14. int  secondint = 0; /// initializing the variables used
  15. cout << "Welcome! This program will calculate the "
  16.      <<"greatest common factor between two positive integers";
  17. do{
  18.     cout << "\nPlease enter the first integer (Enter -1 to exit): ";
  19.     cin >> firstint ;
  20.     cout << "Please enter the second integer (Enter -1 to exit): ";
  21.     cin >> secondint;
  22.     if(firstint == -1 || secondint == -1){///will prevent the loop from going any further
  23.             cout <<"Thank You for using this program!";
  24.         return 0;
  25.     }
  26. cout << "Of the two integers that we given : " << firstint << " and " << secondint;
  27. cout << "The GCF is: " << gcf(firstint, secondint)<<endl; ///function call to calculate the factor
  28. }while(firstint > -1 || secondint > -1);
  29. return 0;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top