First, I have this here:
#include <stdio.h>
#include <stdlib.h>
int main(){
int i=13,w=0,k;
for(k=i-1;k!=1;k--){
if(i%k==0){w=1; break;}
}
if(w==0){ printf("\n%d eh primo",i); }
system("pause");
return 0;
}
In this particular case, calculate whether 13 is prime or not. Now, I want to make one to display the first "n" first cousins, I did this, but it does not work as I expected:
#include <stdio.h>
#include <stdlib.h>
int main(){
int i=2,w=0,k,j=1;
while(1==1){
for(k=i-1;k!=1;k--){
if(i%k==0){w=1; break;}
}
if(w==0){ j++; printf("\n%d eh primo",i); }
if(j==7) break;
i++;
}
system("pause");
return 0;
}
This would be to display the first 7 cousins, but only displays 2 and 3. Why this? I created an integer j
to be incremented whenever prime occurs. When he turns 7 the loop to.
I am grateful to anyone who helps me. Thank you for your attention.