C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-07-2009, 09:45 AM   #1
Registered User
 
Join Date: Nov 2009
Posts: 1
Unhappy C Prog

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.
PreeMaria is offline   Reply With Quote
Old 11-07-2009, 09:53 AM   #2
Registered User
 
Join Date: Jan 2009
Posts: 154
Bitwise?
Subsonics is offline   Reply With Quote
Old 11-07-2009, 01:54 PM   #3
Robot
 
Join Date: Mar 2009
Posts: 100
C - Bitwise Shift Operators - Left Shift, Right Shift
Memloop is offline   Reply With Quote
Old 11-08-2009, 12:24 AM   #4
Registered User
 
rpbear's Avatar
 
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   Reply With Quote
Old 11-08-2009, 10:01 AM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:51 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22