Skip to content

Instantly share code, notes, and snippets.

@Ts-Pytham
Created September 17, 2019 03:28
Show Gist options
  • Save Ts-Pytham/0bb4138ce865e23dc628d96df5ad281e to your computer and use it in GitHub Desktop.
Save Ts-Pytham/0bb4138ce865e23dc628d96df5ad281e to your computer and use it in GitHub Desktop.
Números primos en C++
#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