Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <math.h>
- void printArr(int arr[], int size);
- int main(void)
- {
- int num = get_int("type in an integer: ");
- int num2 = num;
- int count = 0;
- while (num != 1)
- {
- if (num % 2 == 0)
- {
- num /= 2;
- count++;
- //printf("%i\n", num);
- }
- else if (num % 2 != 0)
- {
- num = (num * 3) + 1;
- count++;
- //printf("%i\n", num);
- }
- }
- int arr[count];
- printf("%i", count);
- int i = 0;
- while (num2 != 1)
- {
- if (num2 % 2 == 0)
- {
- num2 /= 2;
- arr[i] = num2;
- }
- else if (num2 % 2 != 0)
- {
- num2 = (num2 * 3) + 1;
- arr[i] = num2;
- }
- i++;
- }
- printArr(arr, count);
- }
- void printArr(int arr[], int size)
- {
- for (int i = 0; i < size; i++)
- {
- printf("%i\n", arr[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement