1. What is the output? #include int main() { for (int x = 10; x >= 0; x--) { int z = x & (x >> 1); if (z) printf("%d ", x); } }
Answers
Answer:
Mate, it's an incomplete program.
If you are coding in C++, and you put it in your dárñèd compiler, it will straightforward ask you to re-program it because you have structural problems.
Re-structure the program, and ask it.
Answer:
#include<stdio.h>
int main()
{
for (int x = 10; x >= 0; x--) {
int z = x & (x >> 1);
if (z)
printf("%d ", x);
}
}
The output of the program is 7 6 3.
Given:
#include<stdio.h>
int main()
{
for (int x = 10; x >= 0; x--) {
int z = x & (x >> 1);
if (z)
printf("%d ", x);
}
}
To Find:
The output of the above program.
Solution:
Here, the above program is in C language.
Here, the whole work of the program has been done within the main() function.
Two integer data type has been taken as x and y.
Then within the main() function a for loop has been run.
Within the for loop,
An initialization value of 10 has been set within the variable x, then a condition has been questioned as if variable x is greater than or equal to 0 and then a decrement of value x has been proposed.
then if the for loop condition gets satisfied, then, z will assign the same value as x and parallelly will use the >> (The bitwise right shift operator) to check if the left-hand side value of & (The bitwise and operator, whether it is equal to 1 only if both of the bits are same) is equal to the right-hand side.
for example; if x =10, then
z = 10 & (10>>1)
or, z = 10 & 5
in this way, the whole screening of x will be done within for loop.
For the rest, z is zero but only for x = 7,6, and 3, z will be non-zero.
That's why,
The output of the program is 7 6 3.
Learn more about the output in C
- https://brainly.in/question/15449576?referrer=searchResults
- https://brainly.in/question/6930984?referrer=searchResults