prime numbers between a sequence

0

The problem is this: I have to get an integer value and calculate the factorial of that number (even there), and pick up and print on the screen the prime numbers that exist between one and the factorial, but I'm having trouble making Can someone tell me what's wrong?

/*Mostrar todos os numeros primos*/
# include<stdio.h>
# include<stdlib.h>

int main()
{
  long int numero,fatorial=1;
  int cont,contador=1,teste,truvs,bash=0,primo;

  scanf("%ld",&numero);

  for(cont=1;cont<=numero;cont++)
  {
    fatorial*=cont;
  }

  printf("FATORIAL -> %ld\n",fatorial);//só printei pra testar a fatoração
//---------DELIMITA A OPERAÇAO---------
  for(contador=2;contador<=fatorial;contador++)
  {
    bash=0;

//--------TESTA  PRIMO------------
    for(teste=1;teste<=contador;teste++)
    {
      bash=0;
//---------ISOLAR O TESTE DE DIVISAO-----------
      while(bash<2)
      {

        // truvs=contador%teste;
        if(contador%teste==0)
        {
          bash++;
           printf("%d\n",bash);
        }
        else
        {
          break;
        }


      }

      if(bash==2)
      {
        printf("%d\n",contador);
      }
      // bash=0;

    }
  }



return 0;
} //Fim do programa
    
asked by anonymous 04.10.2018 / 21:33

1 answer

1

Your test for cousin is wrong. Try:

for (teste=1;teste<=contador;teste++)
{
  bash=0;
  div = 1;
  while(div <= teste)
  {
    if (teste%div == 0)
    {
       bash++;
    }
    div++;
  }
  if (bash==2)
  {
    printf("%d\n", teste); /* teste é primo */
  }
}

Note: it can be optimized.

    
05.10.2018 / 02:01