# A Programming problem faced in an Interview by me



## a_to_z123 (Sep 15, 2010)

Hi guys,

Recently I gave an interview for a company where I faced an unusual question.

The interviewer asked me to make a program which calculates 2^(any 5 digit no.) in any programming language.

The thing is that what data type to take as he specifically mentioned not to take BigInteger or Exponential types.

Please help me out. It'll be better f it be in C++ or Java.

Thanks in advance!


----------



## amohit (Sep 16, 2010)

If you have to make it independent of datatype (and hence language), one possible way I  could think of is using linked lists. 

Regards,
Mohit


----------



## a_to_z123 (Sep 16, 2010)

@amohit: Well I also thought of that, but even then we would have to make calculations and store individual digits.
How is that possible??
Any example??


----------



## Liverpool_fan (Sep 16, 2010)

^ ^ ^
You can use a string or array of integers and make changes on them as you make on a piece of paper.


----------



## Neuron (Sep 16, 2010)

How about this one?Created in C by me 


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
	int pwr,i,val=1,tnpwr=0;
	printf("Enter the power");
		scanf("%d",&pwr);
		for(i=1;i<=pwr;i++)
		{
			val*=2;
			if(val>999999999)
			{
				val/=10;
				tnpwr++;}
		}
		printf("The value is %dx10^%d",val,tnpwr);
		getch();
}


----------



## sagar1099 (Sep 24, 2010)

Hi Neuron  this is sagar
your program gives an error in turbo c++ complier....(Constant expression is out of range)
Please solve this error


----------



## tejaslok (Sep 25, 2010)

> if(val>999999999)


used 9999 worked but didnt get the desired output



Edit : got the output now


----------



## asingh (Sep 25, 2010)

More of a trick questions. Quite a dumb thing to ask in an interview.

Here see this.

It is testing what you "do not know", instead of "what you know".


----------

