#include<stdio.h>
int main()
{
int num;
int result;
printf("Enter the number: ");
scanf("%d",&num);
result = ((num << 2) - (num >> 1));
printf("\nResult = %d",result);
return 0;
}
Explanation
Lets take the input as 10
10 = 0x1010 in hex
So,
0x1010 << 2 = 0x101000 = 40
0x1010 >>1 = 0x0101 = 5
hence
result = 40 - 5 =35 = 10*3.5
You can try with other numbers as well.
No comments:
Post a Comment