Skip to content

Instantly share code, notes, and snippets.

@condef5
Created August 23, 2017 23:40
Show Gist options
  • Save condef5/cde048e05847344d63b11a0fdcc35605 to your computer and use it in GitHub Desktop.
Save condef5/cde048e05847344d63b11a0fdcc35605 to your computer and use it in GitHub Desktop.
Primos repetidos en un array
#include "iostream.h"
#include "conio.h"
/*
Un programa que elimine los numeros primos que se repiten en un vector de N elementos
*/
void main(void)
{
// Variables para los primos
int numPri = 1 ,cantDiv=0;
// Vector
int array[20],temp[20];
// Variables generales
int num,k=0,repNum=0;
cout<<"Ingrese el número de términos";
cin>>num;
for (int i = 0; i < num; ++i){
cout<<"Ingrese el termino "<<(i+1)<<endl;
cin>>array[i];
}
for (int i = 0; i < num; ++i){
cantDiv=0;
for (int j = 1; j <= array[i]; j++){
if(numPri % j == 0){
cantDiv++;
}
if(cantDiv > 2){
break;
}
}
if(cantDiv==2){
repNum = 0;
for (int j = 0; j < k; ++j){
if(temp[j]==array[i]){
repNum++;
}
}
if(repNum==0 || k==0){
temp[k] = array[i]; k++;
}
}else{
temp[k] = array[i]; k++;
}
}
/*Mostrar el arreglo*/
for (int i = 0; i < k; ++i)
{
cout<<temp[i]<<"\t";
}
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment