Abelsor

Semana 3 - Ejercicio 9

Feb 15th, 2022 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. /*
  2.                 Ejercicio 9
  3.     Calcular la raíz cuadrada de un número y escribir su resultado.
  4. */
  5.  
  6. #include<iostream>
  7. #include<math.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     int num;
  14.     float raiz;
  15.    
  16.     cout<<" Ingrese un numero: ";
  17.     cin>>num;
  18.    
  19.     /*
  20.         Utilizando la libreria 'math.h' tenemos dos opciones para hallar la raiz cuadrada:
  21.         1-) Utilizando la funcion sqrt()... sqrt(num) --> raiz del numero
  22.         2-) Utilizando la funcion pow()... pow(num, 0.5) --> raiz del numero (Por propiedad de la raiz como exponente)
  23.     */
  24.     if(num>=0){ // Verificamos que sea un numero positivo o cero
  25.         raiz = sqrt(num);
  26.         cout<<"La raiz de "<<num<<" es: "<<raiz<<endl;
  27.     }
  28.     else
  29.         cout<<num<<" no posee una raiz cuadrada real"<<endl;
  30.    
  31.  }
Add Comment
Please, Sign In to add comment