Created
September 17, 2019 03:28
-
-
Save Ts-Pytham/0bb4138ce865e23dc628d96df5ad281e to your computer and use it in GitHub Desktop.
Números primos en C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdint> | |
/* | |
Algoritmo para imprimir números primos. | |
Creado por Johan Sánchez, 16/09/2019 | |
*/ | |
#define input(a) std::cin>>a; | |
int main(){ | |
uint64_t x, primos = 0; | |
std::cout<<"Ingrese el numero para comprobar si es primo: "<<std::endl; | |
input(x); | |
if (x > 1){ | |
for(int i = 1;i <= x; ++i){ | |
if (x%i == 0 ) | |
++primos; | |
} | |
if (primos == 2) | |
std::cout<<x<<" es un numero primo."; | |
else | |
std::cout<<x<< " no es un numero primo."; | |
} else | |
std::cout<<"El numero debe ser mayor que 1!"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment