Mostrar números primos entre dos intervalos
C++
xxxxxxxxxx
using namespace std;
int main() {
int low, high, i;
bool isPrime = true;
cout << "Enter two numbers (intervals): ";
cin >> low >> high;
cout << "\nPrime numbers between " << low << " and " << high << " are: " << endl;
while (low < high) {
isPrime = true;
if (low == 0 || low == 1) {
isPrime = false;
}
else {
for (i = 2; i <= low / 2; ++i) {
if (low % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime)
cout << low << " ";
++low;
}
return 0;
}
Enter two numbers (intervals): 0 20 Prime numbers between 0 and 20 are: 2 3 5 7 11 13 17 19
Mostrar números primos cuando se ingresa primero el número más grande
C++
xxxxxxxxxx
using namespace std;
int main()
{
int low, high, temp, i;
bool isPrime;
cout << "Enter two numbers (intevals): ";
cin >> low >> high;
if (low > high) {
temp = low;
low = high;
high = temp;
}
cout << "\nPrime numbers between " << low << " and " << high << " are:" << endl;
while (low < high) {
isPrime = true;
if (low == 0 || low == 1) {
isPrime = false;
}
else {
for (i = 2; i <= low / 2; ++i) {
if (low % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime)
cout << low << " ";
++low;
}
return 0;
}
Enter two numbers (intervals): 20 0 Prime numbers between 0 and 20 are: 2 3 5 7 11 13 17 19
Linux - Cómo instalar anc-api-tools
Linux - Cómo instalar curvedns
Linux - Cómo instalar zenmap
Python - Comprobar si un Número es Positivo, Negativo o 0
C - Contar el número de dígitos en un entero
C++ - Comprobar si un número es primo o no
C - Encuentre el número más grande usando la asignación de memoria dinámica
C++ - Comprobar año bisiesto
JavaScript - Comprobar si una cadena comienza y termina con ciertos caracteres
Kotlin - Invertir un número
Linux - Cómo instalar zstd
Linux - Cómo instalar xbitmaps
Kotlin - Redondear un número a n decimales
C++ - Encontrar cociente y resto
Java - Invertir un número
Python - Escritura de archivos de Excel (XLSX)
Kotlin - Encontrar factorial de un número
Java - Crear pirámide y patrón
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month