Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*Programa para calcular o fatorial de numeros primos*\\
- #include <stdio.h>
- //*Funçao que determina se o numero é primo*\\
- int testedoprimo(int num)
- {
- int j=0, div;
- for (div=2;(j<2 && div<=num); div++)
- {
- if (num%div ==0)
- j++;
- }
- if (j>1)
- {
- return 1;
- }
- else return 2;
- }
- //*função que calcula o fatorial dos números primos*\\
- int primosfat(int n)
- { int fat=1;
- while(n!=1)
- {
- if(testedoprimo(n)!=1)
- {
- fat=fat*n;
- }
- n--;
- }
- return fat;
- }
- int main ()
- {
- int numx,fatorial;
- do {
- printf ("Informe um numero primo positivo:\n");
- scanf ("%d",&numx);
- }while (numx<=0);
- fatorial = primosfat(numx);
- printf ("%d# = %d", numx, fatorial);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement