Math, asked by chollangichandu934, 1 month ago

#include<stdio.h>
using namespace std;
int main()
{
for (int x = 10; x = 0; x--) {
int z = x & (x >> 1);
if (z)
printf("%d ", x);
}​

Answers

Answered by debasishsingha190
2

Answer:

#include<stdio.h>

int main()

{

int x,z;

for (x = 10; x >= 0; x--)

{

int z = x & (x >> 1);

if (z)

printf("%d ", x);

}  

}

ANS: 7 6 3

Step-by-step explanation:

Answered by Anonymous
1

#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.

#SPJ3

Similar questions