4
First, I got this:
#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, it calculates whether 13 is prime or not. Now, I want to do one to display the first "n" cousins, I did it, but it doesn’t 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 7 first cousins, but only displays 2 and 3. Why is that? I created an integer j
to be incremented whenever cousin happens. When he turns 7 the loop to.
I am grateful to those who help me. Thank you for your attention.
Which one do you think is best suited to answer that? http://answall.com/q/84040/101, http://answall.com/q/85565/101, http://answall.com/q/85562/101, has others.
– Maniero
I don’t think his question is a duplicate of any of the ones you suggested, @bigown. His case is different.
– Pablo Almeida