Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C program we will calculate the XOR function between two bits(i.e: 0 or 1) and print the result, in the screen. The two bits(i.e: 0 or 1) will be taken from the user.
Discussion:
The XOR gate (sometimes EOR gate, or EXOR gate and pronounced as Exclusive OR gate) is a digital logic gate that gives a true (1 or HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive or; that is, a true output results if one, and only one, of the inputs to the gate is true. If both inputs are false (0/LOW) or both are true, a false output results. XOR represents the inequality function, i.e., the output is true if the inputs are not alike otherwise the output is false. A way to remember XOR is "one or the other but not both".(from Wikipedia) For full article click here.input:
The two bits(i.e. 0 or 1)output:
The XOR of the bits will be printed on the screen.
CODE---->
#include<stdio.h>
#include<conio.h>
main()
{
int bit1,bit2;
printf("Enter the 1st bit : ");
scanf("%d",&bit1);
printf("\nPlease, Enter the 2nd bit : ");
scanf("%d",&bit2);
if(bit1==0||bit1==1&&bit2==0||bit2==1)
{
if(bit1==bit2)
{
printf("\n\nThe result is %d XOR %d = 0",bit1,bit2);
}
else
{
printf("\n\nThe result is %d XOR %d = 1",bit1,bit2);
}
}
else
{
printf("\n\nSorry, You have entered wrong choice/value.");
}
getch();
}
coviogui_be Sarah Thomas https://wakelet.com/wake/ligU6LTLX4ZBhvvPz86k9
ReplyDeletefiapicpolstech