6
I have to create a random number array in a range from 0 to 250, and show which are the primes. This is my code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i,j,n[10];
srand(time(NULL));
for(i=0 ; i < 10 ; i++) {
n[i]=rand()%250;
printf("%d numero: %d\n",i,n[i]);
}
printf("\n");
for (i=0; i<10; i++) {
for (j=2; j<n[i]; j++) {
if (n[i]%j==0) {}
else
printf("O numero %d e primo\n",n[i]);
break;
}
}
}
I’m pretty sure there’s something wrong with taking the rest of the room, but I don’t know what it is.
Hello. Welcome to SOPT. Are you almost sure there’s something wrong, but what’s the mistake? What happens? Don’t check the cousins correctly? Is there an exception? We like to help and explain, but we should know what the mistake is.
– Omni
The mistake was that he was printing numbers that weren’t cousins like cousins, but they’ve solved it down here
– user20153
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero