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 Print the Binary Equivalent of a Decimal Number Using Bitwise Operator and then we will print the 1's Complement of the number on the screen. The Number will be taken from the user.
N:B This Program is created for upto 8-bit binary number(
i.e: Range = 0 to 28-1 = 0 to 255
).
input:
The Number (integers) (i.e. 15,10,128 etc.)output:
The binary equivalent of the decimal number and the 1's complement of the number, will be printed on the screen.
CODE---->
#include<stdio.h>
int main()
{
int n,i,x;
printf(" Please, Enter a Number : ");
scanf("%d",&n);
printf("\n The binary equivalent of the number : \n ");
for(i=7;i>=0;i--)
{
x=n&(1<<i);
if(x==0)
printf("0");
else
printf("1");
}
n=~n;
printf("\n The 1's complement of the number :\n ");
for(i=7;i>=0;i--)
{
x=n&(1<<i);
if(x==0)
printf("0");
else
printf("1");
}
return 0;
}
Comments
Post a Comment