I'm new to programming and I wanted to see if A is equal to B after applying the following operations toward A.`
- If A=1, then A=A.
- If A is even, then A = A/2.
- If A is odd, then A = A*3+1.
output Yes if A is equal to B, No if it's not. I use the following code:
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
getchar();
if (a == 1) {
a = a;
}
else if (a % 2 == 0) {
a = a / 2;
}
else if (a % 2 == 1) {
a = a * 3 + 1;
}
if (a == b) {
printf("Yes\n");
}
else {
printf("No\n");
}
return 0;
}
This works just fine, but I wanted to do the operation as much as possible. e.g. If A=12 and B=5 -> 12/2=6 ->6/2=3->3+2=5. thus A=B. What function do I use to do just that?