prime random numbers in C

0

I have to make a program that can automatically and randomly generate 100 positive integers between 0 and 1000 and display in the console the sum and average of the primes in the created set.

My code is like this and when I want to show a prime number many repeated numbers appear:

#include <stdio.h>
#include <stdlib.h>
#include<time.h>

 int main(int argc, char *argv[]) {

    int number, i, counter, sum, num_divider = 0, divider;
    float media;

    srand(time(NULL));

    for (i = 0; i < 100; i++)
    {
        number = rand() % 1000;

         for(divider = 1; divider <= 1000; divider++)
            {
              if(number % divider == 0)
              {
                num_divider++;
              }



                if(num_divider < 2)
                {
                    sum += number;
                     printf("%02dº gerado %d\n", (i + 1), number);

                    printf("%d", number);

                    counter++;
                }

                num_divider = 0; 
            }

    }

    media = sum / counter;

    puts("");
    printf(" the sum is: %d\n", sum);
    printf(" the average is: %.0f\n", media);       

}
    
asked by anonymous 13.11.2018 / 12:32

0 answers