Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Prime number C code #1756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Algorithms/Prime Number/numprimos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<stdio.h>
int main(){
int vet[9],i,j,div;
for(i=0;i<9;i++){
scanf("%d",&vet[i]); //preenchendo vetor
}
printf("\n\nNumeros primos:\n");
for(i=0;i<9;i++){
div=0;
for(j=1;j<=vet[i];j++){
if(vet[i]!= 1){
if(vet[i]%j==0){ //Calculando se � primo caso nao seja o numero 1
div++;
}
}else{
div =2; //Se for o num 1 ja vai direto
}


}
if(div==2){ //Se for primo s� vai ter dois divosores (1 e o proprio numero)
printf("num: %d\t pos: %d\n",vet[i],i);
}
}
return 0;
}