Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. int main()
  2. {
  3. int zahl, i, j;
  4. int isPrim;
  5. int breakAndCalc;
  6. scanf("%d", &zahl);
  7.  
  8. if(zahl < 2)
  9. {
  10. printf("%d kann nicht zerlegt werden.\n", zahl);
  11. }
  12. else
  13. {
  14. // search from 2 up tu {zahl}
  15. // if {zahl} is a prim number -> break the for loop (isPrim)
  16. // if {zahl} is a NON prim number -> break the loop (breakAndCalc)
  17. for (j = 2; j <= zahl && isPrim == 0 breakAndCalc == 0;j++)
  18. {
  19. // true if prim number
  20. if (j == zahl)
  21. {
  22. isPrim++;
  23. printf("%d ist prim.\n", zahl);
  24. }
  25. else
  26. // true if a non prim number
  27. if (zahl % j == 0)
  28. {
  29. breakAndCalc++;
  30.  
  31. printf("%d ist keine prim.\n", zahl);
  32. }
  33. }
  34.  
  35. // true if non prim number
  36. if (breakAndCalc != 0)
  37. {
  38. for(i=2 ; i <= zahl ; i++)
  39. {
  40. if(zahl % i == 0)
  41. {
  42. zahl = zahl / i;
  43. printf("%d\n", i);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement