Quien me ayuda hacer este algoritmo | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Quien me ayuda hacer este algoritmo

leer un número entero n y calcular e imprimir su inverso 1/n. considerar el caso especial del valor 0,en cuyo caso el programa deberá escribi el mensaje "error-división por cero"

28th Sep 2017, 6:02 PM
tonny
8 Answers
+ 11
using the std:: in this way is a good programming practice when it comes to managing large projects.
28th Sep 2017, 7:10 PM
Babak
Babak - avatar
+ 9
Here, the division is in a specific range [-10, 10] #include <iostream> #include <iomanip> int main(){ std::cout << std::setprecision(8); for (int i = -10; i <= 10; ++i) { if (i == 0.0) std::cout << "NaN"; else std::cout << 1.0/static_cast<double>(i); std::cout << std::endl; } }
28th Sep 2017, 7:07 PM
Babak
Babak - avatar
+ 9
usar el std :: de esta manera es una buena práctica de programación cuando se trata de gestionar grandes proyectos.
28th Sep 2017, 7:11 PM
Babak
Babak - avatar
+ 9
#include <iostream> #include <iomanip> using namespace std; int main(){ cout << setprecision(8); for (int i = -10; i <= 10; ++i) { if (i == 0.0) cout << "NaN"; else cout << 1.0/static_cast<double>(i); cout << endl; } }
28th Sep 2017, 7:13 PM
Babak
Babak - avatar
+ 9
¿Quieres decir de esta manera? #include <iostream> using namespace std; int main(){ double n = 0.0; cout << "Enter a number: "; cin >> n; if (n == 0) cout << "Inf"; else cout << 1.0 / n; }
28th Sep 2017, 8:47 PM
Babak
Babak - avatar
+ 3
#include <stdlib.h> #include <iostream> int main(){ float n = 0; if(n == 0){ std::cout<<"Error"; }else{ std::cout<<1/n; } return 0; }
28th Sep 2017, 6:20 PM
Dapper Mink
Dapper Mink - avatar
0
std::cout que función cumple
28th Sep 2017, 6:58 PM
tonny
0
a mi se exigen escribir la entrada y que salga el proceso 1por uno no todo el resultado por ejemplo cout<<"ingresar numero"; cin>>n;
28th Sep 2017, 7:52 PM
tonny