Comprobar si un número de dos cifras es primo [ESP-ENG] | C++

COVER.jpg

Saludos, por acá traigo otro programita, en esta ocasión también de la universidad, del semestre pasado. Su función es recibir un número de 2 dígitos y decir si es primo o no, contiene una validación para evitar números de 3 cifras y de ingresar uno de 1 cifra mostrará el listado de números primos en el rango de 1-9.

Curiosamente en aquel momento no incluí el 0 entre las validaciones, cuestión a tomar en cuenta para evitar errores.

Greetings, here I bring another little program, this time also from the university, from last semester. Its function is to receive a 2 digit number and say if it is prime or not, it contains a validation to avoid 3 digit numbers and if you enter a 1 digit number it will show the list of prime numbers in the range of 1-9.

Curiously at that time I did not include the 0 among the validations, question to take into account to avoid errors.

Programación c++.png

Usé la librería iostream, conio y stdio, aunque esta última pueden omitirla, en aquel entonces probablemente usé una plantilla, lo bueno de volver a ojear este código es que podemos corregir los detalles que en aquel momento no vimos.

Dentro del main tenemos tres variables, un contador, uno para recibir el número a analizar y el último para analizar el número ingresado a través del operador módulo, que nos muestra el residuo de la división correspondiente, como dije en otros posts de este tipo, es un operador recurrente en estos ejercicios pequeños.

Los divisores que tomé en cuenta fueron 2,3,5,7,9, el número pasa por cada uno de ellos y aumenta el contador en 1 cada que el residuo sea 0, es decir sea una división con resultado exacto, lo que nos mostraría que no se cumple la condición para que un número de dos cifras se considere primo.

Una vez realizada la comprobación muestra un texto que dice si es o no primo.

I used the iostream library, conio and stdio, although this last one you can omit it, at that time I probably used a template, the good thing to look again at this code is that we can correct the details that at that time we did not see.

Inside the main we have three variables, a counter, one to receive the number to analyze and the last one to analyze the number entered through the modulus operator, which shows us the remainder of the corresponding division, as I said in other posts of this type, it is a recurrent operator in these small exercises.

The divisors that I took into account were 2,3,5,7,9, the number goes through each one of them and increases the counter in 1 each time that the residue is 0, that is to say it is a division with exact result, which would show us that the condition is not fulfilled so that a number of two digits is considered prime.

Once the check is done, it shows a text that says if it is prime or not.

image.png

image.png

Programación c++.png

image.png

image.png

image.png

Por último les dejo unas capturas de ejecución, si tienen alguna otra corrección, consejo o aporte, será bien recibido ¡Gracias por pasarte por acá!

Abajo puedes ver una tabla con los links a los otros posts sobre este tema, por si quieres ver un poco más.

Fe de erratas: En el código, en el listado de números primos de 1 digito, 9 no debe ser incluído. Esto también se refleja en las capturas de ejecución.

Finally I leave you some screenshots of execution, if you have any other correction, advice or contribution, it will be well received Thanks for stopping by!

Below you can see a table with links to the other posts on this topic, if you want to see a little more.

Correction: In the code, in the listing of 1-digit prime numbers, 9 should not be included. This is also reflected in the execution screenshots.


Nombre de la publicación / Name of the postLINK
Calculador de datos para un triángulo rectángulo en C++1
Concecionario de autos, ejercicio en JAVA2
Calculador de edad básico C++3
Inversor de números de tres cifras4
¿Cuántos números de 3 cifras existen cuya suma sea 10? - ¡Respondiendo a otro usuario! C++6
Calculadora simple, cifra menos significativa y portada simple C++7
Números de 3 cifras cuyo producto de cifras sea igual a 12 C++8
¡Vistazo a BeatUDO! [ESP-ENG] JAVA9

Programación c++.png

Puedes seguirme por acá si lo deseas:
You can follow me here if you want:

Diseño sin título.gif

Cuenta secundaria
(Dibujos, edición y juegos) | Secondary account (Drawings, editing and games)

H2
H3
H4
3 columns
2 columns
1 column
9 Comments
Ecency