anyone help me ? Write a program that request a positive integer as input and th
ID: 3886937 • Letter: A
Question
anyone help me ?
Explanation / Answer
#include <stdio.h>
int main() {
//code
int n, count = 0;
printf("Enter the number : ");
scanf("%d",&n);
if(n <= 1)
printf("Please enter valid number");
else
{
while(n > 1)
{
if(n % 2 == 0)
n = n/2;
else
n = n*3 + 1;
if(n == 1)
break;
else
count++;
}
}
if(count != 0)
printf("Total iterations : %d", count+1);
}
OUTPUT:
Enter the number : 13
Total iterations : 9
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.