![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 1
| 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. |
| PreeMaria is offline | |
| | #2 |
| Registered User Join Date: Jan 2009
Posts: 154
| Bitwise? |
| Subsonics is offline | |
| | #3 |
| Robot Join Date: Mar 2009
Posts: 100
| |
| Memloop is offline | |
| | #4 |
| Registered User Join Date: Nov 2009
Posts: 8
| show a example 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;
}
|
| rpbear is offline | |
| | #5 |
| Registered User Join Date: Jan 2009
Posts: 154
| 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);
|
| Subsonics is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assembly amature question: prog errors | geek@02 | Tech Board | 1 | 10-03-2008 01:35 PM |
| YangHui triangle print test prog? | toysoldier | C++ Programming | 8 | 08-20-2004 08:46 AM |
| Can you press a key to transport you to some place in the prog ? | joeyzt | C++ Programming | 3 | 06-29-2003 05:50 PM |
| Idea: Elevator Prog | gamer4life687 | Contests Board | 0 | 11-15-2002 10:01 PM |
| password prog | ihsir | A Brief History of Cprogramming.com | 10 | 01-06-2002 06:39 AM |