Pz help..!
How can we get a result such 2 if the user enters 1 , 4 if 2, 6 if 3......
without using +,-,/,%,*,pow(),sqrt(),^ these operators..?
Wat is the logic?
Plz help me with this.
Pz help..!
How can we get a result such 2 if the user enters 1 , 4 if 2, 6 if 3......
without using +,-,/,%,*,pow(),sqrt(),^ these operators..?
Wat is the logic?
Plz help me with this.
Bitwise?
Code:#include<stdio.h> #include<stdlib.h> int main(){ int i = 0x1; int n = 0,input = 0,output = 0; scanf("%d",&n); input = n; while(n--) output = input<<1; printf("%d\n",output); return EXIT_SUCCESS; }
Fair enough, I though this was most certainly homework, and if you get a question like this you must have at some point gone over bitwise operators and bitshifts. I don't see how you can give anything else than hint without giving the whole answer away. It's no special logic involved.
You can do this without the while loop and only one variable btw,
Code:scanf("%d", &n); printf("%d\n", n<<1);