New with C programming, question about a loop situation
Hi all,
I'm new to the C language, trying to do an exercise where I have to print the "fifth" bit of a given number (0 to 255). The condition of this exercise is to not use operators of affectation (such as >>x or <<x, etc.).
I need to do it with modulo and divisions.
I'm really blocked, tried many things, and also searched for solutions on the web, but no success so far. If anyone could guide threw, I would be thankful as heck.
Pasting my poorly written code, then I will comment as to what is my idea behind this.
int main(void)
{
int number_user;
int bit;
int i;
printf("Please put an integer between 0 and 255: ");
scanf("%d", &number_user);
i = 0;
while (i <= 4)
{
number_user /= 2;
i++;
}
bit = number_user % 2;
printf ("your fifth bit is %d: \\n", bit);
return EXIT_SUCCESS;
}
Re: New with C programming, question about a loop situation
You already got the answers in your previous thread:
https://forums.codeguru.com/showthre...loop-situation