Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

while !!!!!!!

+2 votes
asked Oct 9 by 최준혁 (140 points)

One of the numbers 1 to 9 is selected and the following operation is performed.
Multiply a given number by 3 first, and if the result is 10 or more, leave only the number of digits in the work and multiply it by 3 again.
Write a program that outputs the number of times multiplied by 3 until the operation is first selecte

TT... plz

#include <stdio.h>

int main(void)
{
    int a = 1;
    
    int count, b;
    
    scanf("%d", &a);
    
    if (a>0, a<10)
    {
        while(b=a)
        { 
            b = a * 3;
        if(b > 10)
        {
            b = b % 10;
            count++;
        }
    }
    printf("%d",count);
}
else if (a<1,a>9)
{
    printf("1에서 9사이의 수 중에서 입력해주세요.");
}
return 0;
}
    

1 Answer

0 votes
answered Oct 11 by takuodoi (140 points)
I am not sure what you want to do.
Suppose user input 2. Then "b" will become 6, 8, 4 and 2. At that time do you want to show 4, the number of operations?

By the way there are several mistakes:

1. condition of while loop
"assignment" operation (=) returns the assigned value. So "b = a" is evaluated as value of a. I think you want to compare "a" and "b". So you should use "equals" operation (==)

2. b is not initialized
You use "b" as while loop condition. But "b" is not initialized at the first loop.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...