Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. //int x;
  6. int i = 0;
  7. //long long int x = rand();
  8. int j =0;
  9.  
  10. int trials;
  11. printf("Enter the Number of trials to run: ");
  12. scanf("%d", &trials);
  13. //printf("%d\n", n);
  14. for (j =0; j< trials; j++){
  15. // while (i < trials){
  16. // printf("%d\n", rand());
  17. // i++;
  18. long long int x = rand();
  19.  
  20.  
  21. while (x != 1){
  22. if (x % 2 == 0){
  23.  
  24. x = x/2;
  25. } else {
  26.  
  27. x = 3*x + 1;
  28.  
  29. printf("%lli\n",x);
  30. i ++;
  31. //printf("The number of steps is: %d", i);
  32. }
  33. } // end while
  34.  
  35. } // end for
  36. printf("The number of steps is: %d", i);
  37. return 0;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement