A Programming problem faced in an Interview by me

a_to_z123

asia://india/ka/bangalore
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

Broken In
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
 
OP
a_to_z123

a_to_z123

asia://india/ka/bangalore
@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

Sami Hyypiä, LFC legend
^ ^ ^
You can use a string or array of integers and make changes on them as you make on a piece of paper.
 

Neuron

Electronic.
How about this one?Created in C by me :smile:


#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

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

asingh

Aspiring Novelist
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".
 
Top Bottom