Advertisement
Abelsor

S4_Ejercicio_4

Mar 1st, 2023 (edited)
444
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. #include<math.h>
  3. using namespace std;
  4. // se valida que sea entero y positivo y el tipo de variable que que va recibir como parametro la funcion
  5. int validar (float n){
  6.    
  7.     do{
  8.         cin>>n;
  9.     }
  10.     while(int(n)!=n or n<=0);
  11.    
  12.     return int(n);
  13. }
  14.  
  15.  
  16. // Se completa el tipo de variable de retorno y el codigo de la funiรณn
  17. int codificado(int n){
  18.     int acumulador = 0;
  19.     int cont = 0;
  20.     while(n>0){
  21.         int digito = (n%10 + 7)%10;
  22.        
  23.         acumulador += digito*pow(10,cont);
  24.        
  25.         n /= 10;
  26.         cont++;        
  27.     }
  28.    
  29.     return acumulador;
  30.    
  31. }
  32. int main(){
  33.     float n;
  34.     int resul, val;
  35.     val = validar(n);
  36.     resul = codificado(val);
  37.     cout<<resul;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement