Advertisement
Jessfelicout

Untitled

May 19th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //*Programa para calcular o fatorial de numeros primos*\\
  2.  
  3. #include <stdio.h>
  4.  
  5. //*Funçao que determina se o numero é primo*\\
  6.  
  7. int testedoprimo(int num)
  8. {
  9. int j=0, div;
  10.  
  11. for (div=2;(j<2 && div<=num); div++)
  12. {
  13. if (num%div ==0)
  14. j++;
  15. }
  16.  
  17. if (j>1)
  18. {
  19. return 1;
  20. }
  21. else return 2;
  22.  
  23.  
  24. }
  25.  
  26. //*função que calcula o fatorial dos números primos*\\
  27.  
  28. int primosfat(int n)
  29. { int fat=1;
  30.  
  31. while(n!=1)
  32. {
  33. if(testedoprimo(n)!=1)
  34. {
  35. fat=fat*n;
  36. }
  37.  
  38. n--;
  39. }
  40. return fat;
  41. }
  42.  
  43.  
  44. int main ()
  45. {
  46. int numx,fatorial;
  47.  
  48. do {
  49.  
  50. printf ("Informe um numero primo positivo:\n");
  51. scanf ("%d",&numx);
  52.  
  53. }while (numx<=0);
  54.  
  55. fatorial = primosfat(numx);
  56.  
  57.  
  58. printf ("%d# = %d", numx, fatorial);
  59.  
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement