Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(void) {
- //int x;
- int i = 0;
- //long long int x = rand();
- int j =0;
- int trials;
- printf("Enter the Number of trials to run: ");
- scanf("%d", &trials);
- //printf("%d\n", n);
- for (j =0; j< trials; j++){
- // while (i < trials){
- // printf("%d\n", rand());
- // i++;
- long long int x = rand();
- while (x != 1){
- if (x % 2 == 0){
- x = x/2;
- } else {
- x = 3*x + 1;
- printf("%lli\n",x);
- i ++;
- //printf("The number of steps is: %d", i);
- }
- } // end while
- } // end for
- printf("The number of steps is: %d", i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement