Write a program to operate OR operation on two integers and display the result.

#include<stdio.h>
#include<conio.h>
int main()
{
	int a,b,c;
	printf("Read the integers from keyboard (a & b):-");
	scanf("%d %d",&a,&b);
	c=a | b;       //OR operator//
	printf("Operation between a & b in c=%d",c);
	getch();
}

/* a=8 b=4 then output c=12*/

The program starts by including the standard I/O header file stdio.h and conio.h header file.

The main() function is defined and three integer variables a, b, and c are declared. a and b are the two numbers input by the user.

The printf() function is used to display the message on the screen, asking the user to input the two integers.

The scanf() function reads in the two integers a and b entered by the user.

The | symbol is used to perform the logical OR operation between a and b and the result is stored in c.

Finally, the printf() function is used to display the result of the OR operation in the variable c on the screen.

For example, if the user inputs a=8 and b=4, then the output will be c=12, because the binary representation of a is 1000, the binary representation of b is 0100, and the binary representation of c is 1100, which is the bitwise OR of a and b.

Thanks

Write a program to operate OR operation on two integers and display the result.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top