Advertisement
Abelsor

S3_Ejercicio_8

Feb 23rd, 2023 (edited)
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.    float num1f, num2f;//para validar
  5.    int num1,num2,mcd;//para calcular
  6.    
  7.    do{
  8.         cin>>num1f;
  9.     }
  10.     while(num1f != int(num1f) or num1f<0);
  11.    
  12.     do{
  13.         cin>>num2f;
  14.     }
  15.     while(num2f != int(num2f) or num2f<0);
  16.    
  17.    num1 = int(num1f);
  18.    num2 = int(num2f);
  19.    
  20.    
  21.     // Calucular m.c.d
  22.    
  23.     int aux;
  24.     bool bandera = true;
  25.    
  26.    if (num2>num1){ // Ordenar mayor
  27.         aux = num2;
  28.         num2 = num1;
  29.         num1 = aux;
  30.     }
  31.    
  32.    
  33.     // Metodo de Divisiones Sucesivas
  34.     while(bandera){
  35.         if(num1%num2 == 0){
  36.             mcd = num2;
  37.             bandera = false;
  38.         }
  39.        
  40.         else{
  41.             aux = num1%num2;
  42.             num1 = num2;
  43.             num2 = aux;
  44.         }
  45.     }
  46.    
  47.     cout<<mcd;
  48.        
  49.     return 0;
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement